Thursday, April 29, 2021

Installing and Configuring Rust




Why Rust?

According to the Stack Overflow surveys, Rust has been the most loved programming language for the last five years in a row.

Most of the people that have tried out Rust would like to continue using it. You might wonder, why Rust become so special and popular amongst developer?


1. Rust Solves Memory Management Problems

System programming usually demands a low-level memory control and with C/C++ manual memory management, this task can prove to be a real nightmare.
Rust has direct access to hardware and memory because it doesn't  require a garbage collector to run continuously in the background.

2. Rust Has Fast and High Performance

Rust's performance is on par with C++ . The absence of garbage collection contributes to Rust's high speeds. Rust does not have runtime checking and the compiler nips the wrong code right in the bud. 

3. Cross-Platform Development 

You can easily build cross-platform solutions that work on a wide range of operating systems like Linux, Windows, macOS and other platforms.

4. Rust Facilitates Web Application Development

There are a lot web framework that we can use it under Rust programming in your web application tech stack such as Rocket, Actix, Nickel and build an API  with those framework.


How to Install Rust?

If you are running on windows, to start using Rust, download the installer, the run the program and follow on screen instructions. You can download RUSTUP-INIT.EXE.

If you are running on ubuntu, run curl https://sh.rustup.rs -sSf | sh in your shell. This downloads and runs rustup-init.sh, which is turn download and runs the correct version of the rustup-init executable for your platform.


Just choose first option for default installation but if you familiar with the rustup installer then you can go with second option.



After that we can configure our current shell by running command  source $HOME/.cargo/env

Finally, you can verify your installation by typing  rustc --version



Hello World

You can type   nano hello.rs and copy this code into nano ide

fn main() {
    println!("Congrats! Your Hello World is running");
}

Then compile your hello.rs by typing rustc hello.rs and run the executable file  ./hello
You will get an output on the screen Congrats! Your Hello World is running