Rust is a multi-paradigm, general-purpose programming language designed for performance and safety, especially safe concurrency. Rust is syntactically similar to
C++, but guarantees memory safety by using a borrow checker to validate references. Overall, it is a language worth learning with a supportive community and hereon in I’ll be documenting my Rust learning journey !
Installing & Understanding the Ecosystem.
🧑💻 Go to rust-lang.org, and simply follow the instructions.
- Install and manage Rust using the
rustuptool. If you already have Rust installed & want to check the version, use :
rustcis the Rust compiler. To update to the current stable version of
rustccompiler, use :
- If you’ve installed Rust using
rustup, it’ll come with
cargo, the Rust package manager.
cargo is stupidly simple,
- To create a new package (project) with
This creates a rust project with a binary program as output.
This program can be ran using
cargo run command while in the project directory.
While creating Library package, use
cargo new with
follow the same procedure as the binary program to compile the library
That’s about it !! You can use your favorite text editor (Vim, VS Code, etc.) with
rustfmt (Rust code formatter) or
RLS (Rust Language Server) or my favorite Rust Analyzer.
Rust is an opinionated language, it always helps to have these tools while developing.
Rust language has excellent and completely free learning resources such as 🔽
I’ve found Jason Orendorff and Jim Blandy’s book
Programming Rust: Fast, Safe Systems Development very useful and would highly recommend it to anyone who seriously wants to learn Rust.
Greeting world (as per tradition) !
To print “Hello World!”, a string of type
&str in Rust we need to use what Rust calls macros. Macro used in Rust to print with newline (
\n) character is
println! (note Rust macros end with
Let’s create package/crate named ‘hello’ for this simple project. Using
This will create package with name ‘hello’. Now edit the
src/main.rs file to 🔽
To run this, use
cargo run command. The output should resemble this 🔽