fix example code

This commit is contained in:
Alexis Beingessner 2015-07-29 17:15:11 -07:00
parent 4c48ffa53e
commit ddb029034b
5 changed files with 9 additions and 7 deletions

View File

@ -137,6 +137,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
Here's a mutable slice: Here's a mutable slice:
```rust ```rust
# fn main() {}
use std::mem; use std::mem;
pub struct IterMut<'a, T: 'a>(&'a mut[T]); 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: And here's a binary tree:
```rust ```rust
# fn main() {}
use std::collections::VecDeque; use std::collections::VecDeque;
type Link<T> = Option<Box<Node<T>>>; 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> { impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
fn next(&mut self) -> Option<Self::Item> { fn next_back(&mut self) -> Option<Self::Item> {
loop { loop {
match self.0.back_mut().and_then(|node_it| node_it.next_back()) { match self.0.back_mut().and_then(|node_it| node_it.next_back()) {
Some(State::Elem(elem)) => return Some(elem), Some(State::Elem(elem)) => return Some(elem),

View File

@ -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 gets dropped at the same time as another, right? This is why we used the
following desugarring of `let` statements: following desugarring of `let` statements:
```rust ```rust,ignore
let x; let x;
let y; let y;
``` ```
```rust ```rust,ignore
{ {
let x; let x;
{ {
@ -25,7 +25,7 @@ let y;
Each creates its own scope, clearly establishing that one drops before the Each creates its own scope, clearly establishing that one drops before the
other. However, what if we do the following? other. However, what if we do the following?
```rust ```rust,ignore
let (x, y) = (vec![], vec![]); let (x, y) = (vec![], vec![]);
``` ```

View File

@ -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 ensuring the parent joins the thread before any of the shared data goes out
of scope. of scope.
```rust ```rust,ignore
pub fn scoped<'a, F>(f: F) -> JoinGuard<'a> pub fn scoped<'a, F>(f: F) -> JoinGuard<'a>
where F: FnOnce() + Send + 'a where F: FnOnce() + Send + 'a
``` ```

View File

@ -114,7 +114,7 @@ implementation:
```rust ```rust
# use std::cmp::Ordering; # use std::cmp::Ordering;
# struct MyType; # 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 { unsafe impl UnsafeOrd for MyType {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
Ordering::Equal Ordering::Equal

View File

@ -12,7 +12,6 @@ pub struct Vec<T> {
cap: usize, cap: usize,
len: usize, len: usize,
} }
# fn main() {} # fn main() {}
``` ```
@ -69,6 +68,7 @@ impl<T> Deref for Unique<T> {
unsafe { mem::transmute(&self.ptr) } unsafe { mem::transmute(&self.ptr) }
} }
} }
# fn main() {}
``` ```
Unfortunately the mechanism for stating that your value is non-zero is Unfortunately the mechanism for stating that your value is non-zero is