Skip to content

vixhnuchandran/rust

Repository files navigation

Basics of Rust

  1. Setting Up the Environment

    • Installing Rust using rustup.
    • Using cargo (Rust’s package manager) for creating and managing projects.
    • Basic commands: cargo new, cargo build, cargo run, cargo test.
  2. Variables and Mutability

    • Declaring variables with let.
    • Understanding immutability by default (let x = 5).
    • Using mut for mutable variables (let mut x = 5).
  3. Basic Data Types

    • Scalar types: i32, f64, bool, char.
    • Compound types: tuples and arrays.
    • String types: String and &str.
  4. Functions

    • Defining functions (fn keyword).
    • Function parameters and return types.
    • Expressions vs. statements in functions.
  5. Control Flow

    • Conditional statements: if, else, else if.
    • Loops: loop, while, and for.
    • Using break and continue in loops.
  6. Ownership

    • Understanding the concept of ownership.
    • The stack vs. the heap.
    • Move semantics (values vs. references).
    • Memory safety without a garbage collector.
  7. Borrowing and References

    • Immutable references (&T).
    • Mutable references (&mut T).
    • Rules of borrowing (one mutable or many immutable references).
  8. Slices

    • Slicing arrays and strings with [start..end].
    • Understanding slice types (&[T], &str).
  9. Enums and Pattern Matching

    • Defining enums.
    • Using match expressions to handle different enum variants.
    • Using if let for simple matches.
  10. Structs

    • Defining and using structs.
    • Tuple structs and unit-like structs.
    • Implementing methods for structs using impl.
  11. Error Handling

    • Using Result<T, E> and Option<T>.
    • Pattern matching on Result and Option.
    • Propagating errors using ?.
  12. Traits

    • Defining traits (similar to interfaces in other languages).
    • Implementing traits for structs and enums.
    • Common traits: Debug, Clone, PartialEq, Default.
  13. Modules and Crates

    • Organizing code using modules (mod keyword).
    • Using external crates with Cargo.toml.
  14. The Standard Library

    • Common collections: Vec, HashMap, Option, Result.
    • String handling and conversions.
    • File I/O basics (std::fs, std::io).