Rollup merge of #34094 - abenga:doc_changes_variable_bindings, r=steveklabnik
Minor changes to variable bindings chapter * In "*... name as another binding, that's currently in scope, will ...*", *" that's currently in scope"* is not a parenthetical element, and the commas can be omitted. * Other minor changes.
This commit is contained in:
commit
31ddf966f5
1 changed files with 7 additions and 6 deletions
|
@ -37,8 +37,8 @@ of our minds as we go forward.
|
||||||
Rust is a statically typed language, which means that we specify our types up
|
Rust is a statically typed language, which means that we specify our types up
|
||||||
front, and they’re checked at compile time. So why does our first example
|
front, and they’re checked at compile time. So why does our first example
|
||||||
compile? Well, Rust has this thing called ‘type inference’. If it can figure
|
compile? Well, Rust has this thing called ‘type inference’. If it can figure
|
||||||
out what the type of something is, Rust doesn’t require you to actually type it
|
out what the type of something is, Rust doesn’t require you to explicitly type
|
||||||
out.
|
it out.
|
||||||
|
|
||||||
We can add the type if we want to, though. Types come after a colon (`:`):
|
We can add the type if we want to, though. Types come after a colon (`:`):
|
||||||
|
|
||||||
|
@ -159,8 +159,9 @@ error: aborting due to previous error
|
||||||
Could not compile `hello_world`.
|
Could not compile `hello_world`.
|
||||||
```
|
```
|
||||||
|
|
||||||
Rust will not let us use a value that has not been initialized. Next, let’s
|
Rust will not let us use a value that has not been initialized.
|
||||||
talk about this stuff we've added to `println!`.
|
|
||||||
|
Let take a minute to talk about this stuff we've added to `println!`.
|
||||||
|
|
||||||
If you include two curly braces (`{}`, some call them moustaches...) in your
|
If you include two curly braces (`{}`, some call them moustaches...) in your
|
||||||
string to print, Rust will interpret this as a request to interpolate some sort
|
string to print, Rust will interpret this as a request to interpolate some sort
|
||||||
|
@ -222,8 +223,8 @@ To learn more, run the command again with --verbose.
|
||||||
```
|
```
|
||||||
|
|
||||||
Additionally, variable bindings can be shadowed. This means that a later
|
Additionally, variable bindings can be shadowed. This means that a later
|
||||||
variable binding with the same name as another binding, that's currently in
|
variable binding with the same name as another binding that is currently in
|
||||||
scope, will override the previous binding.
|
scope will override the previous binding.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let x: i32 = 8;
|
let x: i32 = 8;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue