doc: improve/fix 'let' FAQ
This commit is contained in:
parent
3b2530c748
commit
4665c3bbfa
1 changed files with 5 additions and 4 deletions
|
@ -165,12 +165,13 @@ particularly easy to read.
|
||||||
|
|
||||||
## Why is `let` used to introduce variables?
|
## Why is `let` used to introduce variables?
|
||||||
|
|
||||||
We don't use the term "variable", instead, we use "variable bindings". The
|
Instead of the term "variable", we use "variable bindings". The
|
||||||
simplest way for binding is the `let` syntax, other ways including `if let`,
|
simplest way for creating a binding is by using the `let` syntax.
|
||||||
`while let` and `match`. Bindings also exist in function arguments positions.
|
Other ways include `if let`, `while let`, and `match`. Bindings also
|
||||||
|
exist in function argument positions.
|
||||||
|
|
||||||
Bindings always happen in pattern matching positions, and it's also Rust's way
|
Bindings always happen in pattern matching positions, and it's also Rust's way
|
||||||
to declare mutability. One can also redeclare mutability of a binding in
|
to declare mutability. One can also re-declare mutability of a binding in
|
||||||
pattern matching. This is useful to avoid unnecessary `mut` annotations. An
|
pattern matching. This is useful to avoid unnecessary `mut` annotations. An
|
||||||
interesting historical note is that Rust comes, syntactically, most closely
|
interesting historical note is that Rust comes, syntactically, most closely
|
||||||
from ML, which also uses `let` to introduce bindings.
|
from ML, which also uses `let` to introduce bindings.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue