A deep dive into basics of Rust programming language.
- Section 1: Introduction
- Section 2: Installatiion
- Section 3: Hello World with Rust
- Section 4: Basics Concepts
- Section 5: Ownership with Rust
- Section 6: Data Handling and Pattern Matching in Rust
- Section 7: Error Handling
- Section 8: Conclusion
-
Rust is a systems programming language sponsored by Mozilla which describes it as a "safe, concurrent, practical language", supporting functional and imperative-procedural paradigms.
-
Rust is syntactically similar to C++, but its designers intend it to provide better memory safety while still maintaining performance prevents segfaults, and guarantees thread safety.
- Basic programming experience
- Beginning Programmers
- Advanced Programmers
- Basics Concepts: OOP, ...
- Click on the following link to go to the official installation website: https://www.rust-lang.org/tools/install
- Based on the OS you're using the website assistant will provide you with the installation guide for your machine.
rustup
: The Rust toolchain installercargo
: Rust's package managerrustc
; Rust compiler
Toolchain update + Cargo:
rustup update
fn main() {
println!("Hello, world!");
}
Compile:
rustc .\hello_world.rs
Execute:
\hello_world\hello_world.exe
Why?
- Complex Rust programs need dependencies
Automate your compilation process with cargo
:
- Cargo - the build system and package manager of rust
- build the code
- download libraries your code depends on (dependencies)
To create cargo project execute the command below:
cargo new my_cargo_project --bin
output:
Created binary (application) `my_cargo_project` package
To build & run the project:
cargo build
Then,
cargo run
if any error:
rustc --explain E0382
Where E0382
is the error id
- 04 - Hello World
- 05 - Hello Cargo
- 06 - Variables and Mutability
- 07 - Scalar Data Type - Integer
- 08 - Scalar Data Type - Float
- 09 - Compound Data Type - Tuples
- 10 - Compound Data Type - Arrays
- 11 - Functions
- 12 - Returning value Functions
- 13 - if-else
- 14 - While Loops
- 15 - For Loops
- 20 - Structs
- 21 - Structs Example
- 22 - Method Syntax
- 23 - Enums
- 24 - Enums with mul types
- 25 - Pattern Matching
Some of functionalities that Rust std Libraries(Colletion of Crates)/Modules/Packages covers:
- Core language features: The standard library provides the basic building blocks of the Rust language, such as integers, floats, strings, and booleans.
- Data structures: The standard library provides a variety of data structures, such as vectors, maps, and sets.
- IO: The standard library provides functions for reading and writing data to and from the filesystem, network sockets, and other sources.
- Concurrency: The standard library provides primitives for writing concurrent code, such as threads, mutexes, and condition variables.
- Error handling: The standard library provides a mechanism for handling errors, such as the Result type.