Genesis in Rust: Getting Started
Tags: rust, beginners, webdev, career
Published: 2022-04-16 22:38:45



Rust is a systems programming language that focuses on speed, memory safety, and parallelism. Rust is the super productive, super safe, and super fast language **that breaks the trend of marginal improvements**. It changes the way you think about software development.


Rust puts developers first by providing features that make software development smooth and reliable. This includes maintenance, which is a large part of a project's lifecycle.

This is where Rust shines. Rust combines ease of programming with access to core system configurations. Rust is built with memory-safety, concurrency, and security from the ground up.


Since Rust can run both on the backend (natively) and frontend (via Wasm) of web applications, learning Rust becomes a clear choice for creating performant and reliable web applications that can be accessed anywhere, and on any device.

Rust is used by some of the top tech companies like Amazon, Microsoft Corporation, Dropbox, Cloudflare, Figma, Discord, Mozilla and Facebook to deliver speed and concurrency to their customers.


**Let's look at some core features that make Rust stand out from other programming languages.**

**Performance**

Rust is a really fast and memory-efficient language. It offers fine-grained control of memory management and has a minimal standard library. So it can perform well with critical services, within embedded devices, and easily be integrated with other languages.

**Security**

Using Rust eliminates an entire class of security vulnerabilities from software applications. This helps companies build applications with better performance and higher security. This is a great relief to any new programmer, as it reduces the burden while compiling.

**Concurrency**

Concurrency is when two or more tasks start, run, and complete in overlapping time. Database operations are a great example to explain concurrency. When thousands of users are using your application at the same time to perform different actions, your database handles them concurrently. Concurrency is a key concept when it comes to scaling applications.


**_This article will guide you through setting up Rust and getting started._**


## Getting started

Now that you understand the core features of Rust, let's setting up. You can find [installation instructions here](https://www.rust-lang.org/tools/install) follow the instructions to continue the installation.

Now open your IDE, I use WebStorm as my IDE because it provides a robust, fast, and flexible static code analysis and actually provides a lot of support for Rust.

Let's start with a simple “Hello World!” function. Create a new file with the name "main.rs" extension


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2m7tv1bugk2l72qa55vm.png)

Now open the main.rs and type the following code:

```
fn main( ) {
    println!("Hello, world!");
}
```
- _**fn** is used to declare a function in Rust_
- _The **main** function is special: it's the beginning of every Rust program_
- _The line ends with a semicolon **(;)**. The ; indicates that this expression is over, and the next one is ready to begin. Most lines of Rust code end with a **;**_

Save the file, open your terminal and enter the following commands:

```
$   rustc main.rs
$   ./main
```
- _Before running a Rust program, you have to compile it. You can use the Rust compiler by entering the rustc command and passing it the name of your source file_

And you should see the string **Hello, world!** print to the terminal. If you did, then congratulations! You've officially written a your first Rust program 👏🎊


## Project management with Cargo

To create your first project using Cargo, you invoke the cargo executable with keyword new and lastly with the name of the project like so:

```
$   cargo new project-name
```

Let’s check out what Cargo has generated for us:

```
$   cd project-name
$   tree .
 .
 ├── Cargo.toml
 └── src
       └── main.rs

1 directory, 2 files
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51433y2lpn35nfbbqgx8.png)

The **main.rs** is our projects main file, the entry for our app. Here's what main.rs contains:

```
fn main( ) {
    println!("Hello, world!");
}
```
- _Cargo generated a **hello, world!** for us_

Let’s take a closer look at **Cargo.toml** :

```

   [package]
   name = "project-name"
   version = "0.1.0"
   authors = ["email, inferred from Git"]
   edition = "2018"

   # See more keys and their definitions at https://doc.rustlang.org/cargo/reference/manifest.html

   [dependencies]
```
- _This is called a manifest, and it contains all of the metadata that Cargo needs to compile your project._


## Now let’s build and run the code

To build and run your project, call cargo run in your project directory root:

```
$   cargo run
```
You should get this output :


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1m3hhrcc4puv77fo0rep.png)


## Resources to help you

Afterward, practice coding with [Exercism](https://exercism.org/users/sign_in) to improve your Rust chops together with reading a more extensive resource like [the Rust book](https://doc.rust-lang.org/book/) (standard choice) or [Easy Rust](https://dhghomon.github.io/easy_rust/) (accessible choice). At any point where you feel that you are almost ready to build your own toy applications, just go ahead and do it. There are some nice online communities to ask for feedback and support, so don’t be worried about getting stuck!

---

☞ Follow me on [Twitter](https://twitter.com/danmugh) & [Linkedin](https://www.linkedin.com/in/dan-mugisho-m-b20b37228/)

☞ Kindly subscribe for my upcoming articles