mirror of
https://github.com/darkicewolf50/RustBrock.git
synced 2025-07-06 02:57:13 -06:00
.github
.obsidian
HelloWorld
branches
functions_rust
guessing_game
hello_cargo
loops
ownership
rectangles
.gitignore
Collection of Common Data Structs.md
Constants.md
Crates.md
Data Types.md
Enums.md
Error Handling.md
Generic Types Traits and Lifetimes.md
Generics.md
Hash.md
Lifetimes.md
Modules and Use.md
Packages.md
Paths.md
Primitives.md
Project Organization.md
README.md
Reducing_Code_Duplication.md
RustBrock.code-workspace
String.md
Structures.md
Traits.md
Variables.md
Vector.md
data_types.md
ownership.md
769 B
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