DEV Community

Cover image for Entering The Rust Universe

Entering The Rust Universe

Last week in my newsletter, 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.

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

As we land on the Rust homepage, 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

You can play around with Rust completely online with the Rust playground.

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

Once you โ€˜Enterโ€™ to approve the installation, the process will be completed and you can test it by checking the cargo version -

Rust-4

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

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

Cargo Help

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

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

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

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.

Subscribe to my weekly newsletter on software development, my journey with code, and many other useful information to elevate your programming career.

Top comments (0)