Files
.gitea
.github
.obsidian
HelloWorld
actix_web_learning
adder
branches
functions_rust
guessing_game
hello-async
hello_cargo
loops
minigrep
ownership
rectangles
.gitignore
Any Number of Futures.md
Applying Async.md
Async, Await, Futures and Streams.md
Cargo Workspaces.md
Cargo and Cratesio.md
Closures.md
Collection of Common Data Structs.md
Concurrency.md
Constants.md
Crates.md
Custome Build Profiles.md
Data Types.md
Deref Trait.md
Drop Trait.md
Enums.md
Error Handling.md
Extending Cargo.md
For later baja.md
Futures and Async.md
Futures in Sequence.md
Generic Types Traits and Lifetimes.md
Generics.md
Hash.md
Improving The IO Project.md
Install Binaries.md
Iterators and Closures.md
Iterators.md
Leaky Reference Cycles.md
Lifetimes.md
Modules and Use.md
Packages.md
Passing Data Between Threads.md
Paths.md
Primitives.md
Project Organization.md
Publishing libraries.md
README.md
Reducing_Code_Duplication.md
Ref Cell Mutability.md
Reference Counter Smart Pointer.md
RustBrock.code-workspace
Shared State Concurrency.md
Simultaneous Code Running.md
Smart Pointers.md
String.md
Structures.md
Sync and Send.md
Test Controls.md
Test_Organization.md
Tests.md
The Performance Closures and Iterators.md
Traits for Async.md
Traits.md
Using Box on the Heap.md
Variables.md
Vector.md
Writing_Tests.md
data_types.md
ownership.md
RustBrock/Variables.md

769 B

Variables

  • Are Immutable by default
  • can be inferred but sometimes needs explicit typing
    let foo = 5;
  • Need to add mut keyword to enable rewriting, generally avoid unless actually used
    let mut bar = 6;

SHADOWING

Cannot have mutable shadows

allows for reuse of namespace instead of spaces_str and spaces_num

    let spaces = " _ _ ";
    let spaces = spaces.len();
    // will output 5 instead of " _ _ " beacuse that is how long it is
    // the shadow of spaces (first) wont be printed until the overshadow of spaces goes out of scope
    println!("{spaces}"); // output: 5

not allowed shadow

    let mut spaces = " _ _ ";
    spaces = spaces.len();

cannot change type of variable once declared