Entering The Rust Universe
Tags: rust, programming
Published: 2024-02-03 06:17:58

Last week in my [newsletter](https://bitfumes.com/newsletters), I talked about the amazing language Rust - and why everyone needs to start learning it for 2024. 

If you missed reading it, you can catch up on it [here](https://bitfumes.com/newsletters). 

Rust is one of the fastest growing and highly performant languages of modern times. 

Launched in 2015 for the public, Rust was meant to be a replacement language for systems level programming languages, and it has not failed to live up to its expectations. 

So much so that Rust now has a fully thriving ecosystem built around it with many frameworks and libraries to support the development of apps across all platforms. 

Why wait then? Let’s get started with setting up our first Rust project 🚀

![Rust-1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hy8kinrzxrazsjmlfkc7.png)

As we land on the [Rust homepage](https://www.rust-lang.org/), we see a compact, welcoming landing page with the latest release version mentioned on the right with the link to documentation in the Get Started button. 

Once we enter the documentation, we have many different options available to start implementing Rust. 

![Rust-2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hltnihxhkzjyed4ebkyb.png)

You can play around with Rust completely online with the [Rust playground](https://www.rust-lang.org/). 

Let’s install Rust on our system. Open up your terminal and run this curl command - 

`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`

Once you run this command, you will be presented with a welcome message along with the location of where Rust toolchains and metadata, `cargo` the package manager will be installed, and the information about the PATH variables added, like so - 

![Rust-3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y840byc8vru60m7qeqwr.png)


Once you ‘Enter’ to approve the installation, the process will be completed and you can test it by checking the cargo version - 

![Rust-4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnb24aqod85b9rx8i0oy.png)


## Building the first Rust project -

Now, as mentioned, `cargo` is the official package manager for Rust and it is very handy. From accessing the documentation, help pages, to creating a new Rust project right from the CLI, cargo is very useful. Here are some quick commands for reference - 

![Cargo run](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dgyg1l9v2t6k8htbc4p3.png)

You can also type `cargo –help` to see a comprehensive list of commands that come with cargo for quick navigation - 


![Cargo Help](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu7qo6no6wr19vlx5lrh.png)


With that done, let’s create our first Rust project - 

In your terminal, `cd` into the folder/directory where you want to create your new Rust project and run the command - `cargo new learn-rust` 

Open this project folder in your code editor. You can see that the project has a few starter files generated by `cargo` command -


![Rust project structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ep0u6k9jd2p88kh7rllh.png)



Inside the `src` folder, we have `main.rs` file where `.rs` is the extension for Rust files, and then a `Cargo.toml` file which is the configuration file for the project. It is similar to YAML and JSON files, but just a bit easier to read due to its simpler semantics. This file is what we call the “manifest” file for Rust. It contains the metadata and dependencies for the entire project. This sounds similar to the `package.json` file in ReactJS/NodeJS projects, doesn’t it? 

The main.rs file is where we write all our application code. Again, similar to index.js file.


![Cargo.toml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/glh2nnfd5edha4wgb676.png)



We’ll come back to these lines of code and their meanings very soon. Let’s first run our project. 

We use the command `cargo run` to generate the output of our `main.rs` file above. Once we do, we get the following output - 


![Main.rs file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bkbhjyaocmlk26lpwxmo.png)



You can see the output “Hello, world!” in the terminal 🥳 Congratulations, you just ran your first Rust program 🚀

You can notice that a new folder target has been created and this is where our debug files, logs, and output file will be stored. 

And that is it for this tutorial. In the next blog, we’ll learn more about `cargo` package manager and the magic it weaves ✨

I have also published a detailed video on this topic in my YouTube channel - [watch it here](https://youtu.be/XBoggGeBWSA?si=8hA5dMjsoTEi306B). 

[Subscribe to my weekly newsletter](https://youtu.be/XBoggGeBWSA?si=8hA5dMjsoTEi306B) on software development, my journey with code, and many other useful information to elevate your programming career.