

Let's run the program and pass two arguments.

Let item = std::env::args().nth(2).expect("Please specify an item") Replace the content of main with the following: let action = std::env::args().nth(1).expect("Please specify an action") We will start by reading the arguments the user inputs and printing them out. Our goal is to have our CLI accept two arguments: the first one which will be the action, and the second one which will be the item. To build and run it, simply execute cargo run. As you may guess, this program is the Rust version of " hello world!".
Rust language book how to#
fn is how to declare functions while the ! in println! is a macro. Like many other languages, Rust has a main function that will be run first. We will work on the src/main.rs file for the rest of this tutorial, so go ahead and open it. You should see two files in there: $ tree. Now navigate to the newly created directory and list its content. In my case I have decided to name my project "todo-cli" so I can run: $ cargo new todo-cli To start a new project, navigate to where you want your project to be created then simply run cargo new. Cargo is the Rust package manager, and to JavaScript developers it'll feel like npm or yarn. There, you will also find instructions to integrate the language with your favorite editor for a better experience.Īlong with the Rust compiler itself, Rust comes with a tool called Cargo. To do so please follow the instructions you find on the getting started page of the official Rust website.
Rust language book download#
To get started, download Rust onto your computer. In that case you can omit to have it as a return. This means that we have to type semicolons (" ") ourselves unless it is the last statement of a function.

It has no garbage collector, which makes its performance really good. Rust was designed by Mozilla and is considered a system programming language (like C or C++).

It's also been voted the most loved programming language on StackOverflow's developer survey each year since 2016. Since its first open-source release in 2015, the Rust programming language has gained a lot of attention from the community.
