Rollup merge of #29168 - aarzee:master, r=steveklabnik
Remove leading newlines; replace lines containing only whitespace with empty lines; replace multiple trailing newlines with a single newline; remove trailing whitespace in lines. This PR was created semiautomatically.
This commit is contained in:
commit
ea3bf79bac
32 changed files with 71 additions and 71 deletions
|
|
@ -73,7 +73,7 @@ hello.rs:4 }
|
|||
```
|
||||
|
||||
This [unfortunate error](https://github.com/rust-lang/rust/issues/22547) is
|
||||
correct: documentation comments apply to the thing after them, and there's
|
||||
correct: documentation comments apply to the thing after them, and there's
|
||||
nothing after that last comment.
|
||||
|
||||
[rc-new]: https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.new
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ kinds of things `foo` could be: `self` if it’s just a value on the stack,
|
|||
`&self` if it’s a reference, and `&mut self` if it’s a mutable reference.
|
||||
Because we took the `&self` parameter to `area`, we can use it just like any
|
||||
other parameter. Because we know it’s a `Circle`, we can access the `radius`
|
||||
just like we would with any other `struct`.
|
||||
just like we would with any other `struct`.
|
||||
|
||||
We should default to using `&self`, as you should prefer borrowing over taking
|
||||
ownership, as well as taking immutable references over mutable ones. Here’s an
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ philosophy, memory safety, and the mechanism by which Rust guarantees it, the
|
|||
|
||||
> You may have one or the other of these two kinds of borrows, but not both at
|
||||
> the same time:
|
||||
>
|
||||
>
|
||||
> * one or more references (`&T`) to a resource,
|
||||
> * exactly one mutable reference (`&mut T`).
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ With that in mind, let’s learn about ownership.
|
|||
# Ownership
|
||||
|
||||
[Variable bindings][bindings] have a property in Rust: they ‘have ownership’
|
||||
of what they’re bound to. This means that when a binding goes out of scope,
|
||||
of what they’re bound to. This means that when a binding goes out of scope,
|
||||
Rust will free the bound resources. For example:
|
||||
|
||||
```rust
|
||||
|
|
@ -158,8 +158,8 @@ has no pointers to data somewhere else, copying it is a full copy.
|
|||
|
||||
All primitive types implement the `Copy` trait and their ownership is
|
||||
therefore not moved like one would assume, following the ´ownership rules´.
|
||||
To give an example, the two following snippets of code only compile because the
|
||||
`i32` and `bool` types implement the `Copy` trait.
|
||||
To give an example, the two following snippets of code only compile because the
|
||||
`i32` and `bool` types implement the `Copy` trait.
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ So when we add the curly braces:
|
|||
```rust
|
||||
let mut x = 5;
|
||||
|
||||
{
|
||||
{
|
||||
let y = &mut x; // -+ &mut borrow starts here
|
||||
*y += 1; // |
|
||||
} // -+ ... and ends here
|
||||
|
|
@ -306,7 +306,7 @@ which was invalid. For example:
|
|||
|
||||
```rust,ignore
|
||||
let y: &i32;
|
||||
{
|
||||
{
|
||||
let x = 5;
|
||||
y = &x;
|
||||
}
|
||||
|
|
@ -323,7 +323,7 @@ error: `x` does not live long enough
|
|||
note: reference must be valid for the block suffix following statement 0 at
|
||||
2:16...
|
||||
let y: &i32;
|
||||
{
|
||||
{
|
||||
let x = 5;
|
||||
y = &x;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,8 +102,8 @@ println!("");
|
|||
This prints:
|
||||
|
||||
```text
|
||||
229, 191, 160, 231, 138, 172, 227, 131, 143, 227, 131, 129, 229, 133, 172,
|
||||
忠, 犬, ハ, チ, 公,
|
||||
229, 191, 160, 231, 138, 172, 227, 131, 143, 227, 131, 129, 229, 133, 172,
|
||||
忠, 犬, ハ, チ, 公,
|
||||
```
|
||||
|
||||
As you can see, there are more bytes than `char`s.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue