Rust Tutorial

This series takes you from writing your very first Rust program to mastering the core concepts that make Rust unique. Each tutorial is short, focused, and builds upon the previous one.

Section 1. Getting Started with Rust #

Section 2. Rust Basics #

  • Comments – Learn how to explain your code using comments.
  • Variables and Immutability – Understand how variables work in Rust, why they are immutable by default, and when to use mut.
  • Data Types in Rust – Explore integers, floating-point numbers, Booleans, characters, and strings.
  • Constants – Define values that never change using constants.
  • Shadowing – Shadowing means declaring a new variable with the same name as an existing one. The new variable shadows (hides) the old one, and from that point forward, the old variable is no longer accessible.
  • Basic Operators – Learn arithmetic, comparison, and logical operators in Rust.

Section 3. Control Flow #

  • If-else Statement & Expressions – Write conditional logic with if, else if, and else.
  • Loop – Learn how to execute a block repeatedly using loop statement.
  • While loop – Show you how to execute a code block as long as a condition is true.
  • For loop – Learn how to repeat a code block a specified number of times using a for loop.
  • Pattern Matching with match – Discover Rust’s powerful match expression for branching logic.
  • Shorthand Matching with if let and while let – Learn how to write concise and readable pattern matches.

Section 4. Functions and Scope #

  • Functions – Learn function syntax, naming rules, and how to call them.
  • Expressions vs. Statements – Understand the difference between statements and expressions in Rust.
  • Variable scopes – Learn how variable scope works and why it matters in memory safety.

Section 5. Ownership and Borrowing #

Section 6. Structs and Enums #

Section 7. Collections and Strings #

  • Strings and String Slices – Learn the difference between String and &str, and when to use each.
  • Vectors – Work with dynamic arrays using vectors.
  • HashMap – Store key-value pairs using HashMap.
  • Iterating Over Collections -Use iterators to loop through strings, vectors, and maps.

Section 8. Error Handling #

  • Panic and Unrecoverable Errors – Understand how Rust handles fatal errors with panic!.
  • Using Result for Error Handling – Handle recoverable errors with Result and match.
  • The ? Operator – Learn how to simplify error handling with the ? operator.
  • Common Error Handling Patterns – Best practices for dealing with errors in Rust.

Section 9. Modules and Packages #

  • Organizing Code with Modules – Split your program into smaller, organized pieces.
  • The use Keyword – Learn how to bring names into scope.
  • Creating and Using Crates – Package and share your Rust code.
  • Cargo Basics – Use Cargo to build, run, test, and document your project.

Section 10. Traits and Generics #

  • Defining and Implementing Traits – Learn how to define traits and add them to types.
  • Default Methods in Traits – Use default behavior for trait methods.
  • Generics in Functions and Structs – Write flexible code with generics.
  • Trait Bounds and Constraints – Control what types can be used with generics.

Section 11. Smart Pointers and Memory Safety #

  • The Stack vs. The Heap – Understand memory allocation in Rust.
  • Boxed Values with Box<T> – Learn when and why to use heap allocation.
  • Reference Counting with Rc<T> – Share data across multiple owners safely.
  • Interior Mutability with RefCell<T> – Allow mutation in otherwise immutable structures.

Section 12. Concurrency in Rust #

  • Threads and the thread Module – Create and manage threads in Rust.
  • Message Passing with Channels – Communicate safely between threads.
  • Shared State with Arc and Mutex – Use atomic reference counting and mutual exclusion for shared data.
  • Preventing Data Races – See how Rust’s compiler eliminates data race bugs.

Section 13. Asynchronous Programming #

  • Async and Await in Rust – Introduction to writing asynchronous functions.
  • Futures and Runtimes – Understand how async tasks are executed.
  • Using Tokio or async-std -Run async applications with popular runtimes.

Section 14. Building Real Applications #

  • Writing a Command-Line Tool – Build a CLI app using the Clap crate.
  • Building a Web API – Create a REST API using Actix Web or Axum.
  • Using External Crates from crates.io -Find and integrate community libraries into your projects.

Section 15. Testing and Documentation #

  • Writing Unit Tests – Write simple tests with the #[test] attribute.
  • Running Tests with Cargo – Use cargo test to manage and run tests.
  • Documentation Comments -Write documentation with triple-slash /// comments.
  • Generating HTML Docs – Create and view docs with cargo doc.

Section 16. Next Steps #

  • Writing Idiomatic Rust – Best practices and style conventions.
  • Understanding Compiler Errors – How to read and fix compiler error messages effectively.
  • Where to Learn More – Books, Rust RFCs, and advanced topics for further study.