Rust/Variable/let
- Examples
letcan only be used in function local scope- unlike
const, it's not required to have a type annotation, but Rust/analyzer will likely make it difficult to create a new one without inserting the type, e.g. it will changelet foo = 1tolet foo: u32 = 1 - Rust/mut -
let mut count = FOUR; comparison - Typescript's
letkeyword vs Rust'sletkeyword- Typescript
let - Rust
let- immutable by default
- reassignment is only allowed
- 1 - if followed with Rust/mut keyword
- 2 - if
letis redeclared, which is what rustacians call Rust/Variable/Shadowing
- Typescript
doesn't need initialization