fix example code
This commit is contained in:
parent
4c48ffa53e
commit
ddb029034b
@ -137,6 +137,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
|
||||
Here's a mutable slice:
|
||||
|
||||
```rust
|
||||
# fn main() {}
|
||||
use std::mem;
|
||||
|
||||
pub struct IterMut<'a, T: 'a>(&'a mut[T]);
|
||||
@ -170,6 +171,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
|
||||
And here's a binary tree:
|
||||
|
||||
```rust
|
||||
# fn main() {}
|
||||
use std::collections::VecDeque;
|
||||
|
||||
type Link<T> = Option<Box<Node<T>>>;
|
||||
@ -262,7 +264,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
|
||||
}
|
||||
|
||||
impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
fn next_back(&mut self) -> Option<Self::Item> {
|
||||
loop {
|
||||
match self.0.back_mut().and_then(|node_it| node_it.next_back()) {
|
||||
Some(State::Elem(elem)) => return Some(elem),
|
||||
|
@ -8,12 +8,12 @@ when we talked about `'a: 'b`, it was ok for `'a` to live *exactly* as long as
|
||||
gets dropped at the same time as another, right? This is why we used the
|
||||
following desugarring of `let` statements:
|
||||
|
||||
```rust
|
||||
```rust,ignore
|
||||
let x;
|
||||
let y;
|
||||
```
|
||||
|
||||
```rust
|
||||
```rust,ignore
|
||||
{
|
||||
let x;
|
||||
{
|
||||
@ -25,7 +25,7 @@ let y;
|
||||
Each creates its own scope, clearly establishing that one drops before the
|
||||
other. However, what if we do the following?
|
||||
|
||||
```rust
|
||||
```rust,ignore
|
||||
let (x, y) = (vec![], vec![]);
|
||||
```
|
||||
|
||||
|
@ -188,7 +188,7 @@ data on their parent's stack without any synchronization over that data by
|
||||
ensuring the parent joins the thread before any of the shared data goes out
|
||||
of scope.
|
||||
|
||||
```rust
|
||||
```rust,ignore
|
||||
pub fn scoped<'a, F>(f: F) -> JoinGuard<'a>
|
||||
where F: FnOnce() + Send + 'a
|
||||
```
|
||||
|
@ -114,7 +114,7 @@ implementation:
|
||||
```rust
|
||||
# use std::cmp::Ordering;
|
||||
# struct MyType;
|
||||
# pub unsafe trait UnsafeOrd { fn cmp(&self, other: &Self) -> Ordering; }
|
||||
# unsafe trait UnsafeOrd { fn cmp(&self, other: &Self) -> Ordering; }
|
||||
unsafe impl UnsafeOrd for MyType {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
Ordering::Equal
|
||||
|
@ -12,7 +12,6 @@ pub struct Vec<T> {
|
||||
cap: usize,
|
||||
len: usize,
|
||||
}
|
||||
|
||||
# fn main() {}
|
||||
```
|
||||
|
||||
@ -69,6 +68,7 @@ impl<T> Deref for Unique<T> {
|
||||
unsafe { mem::transmute(&self.ptr) }
|
||||
}
|
||||
}
|
||||
# fn main() {}
|
||||
```
|
||||
|
||||
Unfortunately the mechanism for stating that your value is non-zero is
|
||||
|
Loading…
x
Reference in New Issue
Block a user