Post

Rust

FeatureImmutable Variable (let)Constants (const)
EvaluationRuntimeCompile-time
TypeOptional (inferred)Required
ScopeBlock-localGlobal or local
Use CaseRuntime values, immutable after assignedFixed values, known at compile time

Shadowing effectively creates a new variable with the same name as an existing one, allowing the reuse of the variable name while potentially altering its type or value.

1
2
let spaces = "    ";
let spaces = spaces.len();

Ownership

Each value in Rust has one and only one owner at a time.

drop: RAII

Variable bindings:

  • Move semantics: default
  • Copy semantics: bit-wise copy

The following actions can possibly transfer (move) ownership:

  • Assignment
  • Passing a variable to a function
  • Returning values

Enum

1
2
3
4
enum Option<T> {
    None,
    Some(T,
}
This post is licensed under CC BY 4.0 by the author.