- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rust programming language – Getting Started
The first part of getting hands-on experience with Rust is installing Rust. In order to install Rust, we need a Rust installer.
Rustup is a version management tool and also an installer that helps in installing Rust in your local machine.
If you’re running Linux, macOS, or another Unix-like OS, then we simply need to run the following command in the terminal −
curl --proto ‘=https’ --tlsv1.2 -sSf https://sh.rustup.rs | sh
The above command will install Rust on your local machine.
If you are on Windows, then you can download the .exe file from this link rustup-init.exe
Keeping Rust Updated
Though Rust is updated frequently, but you can always make sure that it is up-to-date by running the following command −
Cargo: the package manager
- Once you’ve installed Rustup, you’ll also get the latest version of Rust’s package manager and build tool which is also known as Cargo. Cargo is essential for Rust, and it allows us to perform the following operations −
- build your project with − cargo build
- run your project with − cargo run
- Test your project with − cargo test
- Build documentation for your project with − cargo doc
We can test whether we’ve correctly installed Rust and Cargo by running the following command in any terminal of our choice −
Creating a new project
Let’s make use of Cargo to create a new Rust project. In your terminal, run the following command −
cargo new hello-tutorialspoint
The above command will generate a new directory called hello-tutorialspoint with the following files −
hello-tutorialspoint |-- Cargo.toml |-- src |-- main.rs
- Cargo.toml − the manifest file for Rust.
- src/main.rs − where your application code will be written.
It’s always a tradition that we write a “Hello, world!” program whenever we are learning a new programming language. In Rust, Cargo provides us with the same, we just need to run the following command in our terminal −
The above command will generate a “Hello, world!” project. In order to run the project, we need to move into the new directory that we made and run the following command in the terminal −
After running this command, you’ll have something similar to this −
Compiling hello-tutorialspoint v0.1.0 (/Users/immukul/hello-tutorialspoint) Finished dev [unoptimized + debuginfo] target(s) in 2.39s Running `target/debug/hello-tutorialspoint` Hello, world!
- Rust programming language – Applications
- Rust Programming Language – Big Features
- Rust programming language – An Overview
- Downsides of Rust Programming Language
- Functions in Rust programming language
- How is Rust programming language used?
- Why is Rust Programming language loved so much?
- Getting started with coding
- Python Getting started with psycopg2-PostgreSQL
- Python - Getting started with SymPy module
- Constants in Rust Programming
- Casting in Rust Programming
- Channels in Rust Programming
- Arrays in Rust Programming
- HashSet in Rust Programming