Skip to content

Commit

Permalink
rollup merge of rust-lang#19304: steveklabnik/gh19302
Browse files Browse the repository at this point in the history
Fixes rust-lang#19302.

Also made a minor cosmetic change to bring the example in line with style guidelines.
  • Loading branch information
alexcrichton committed Nov 27, 2014
2 parents 69e7554 + 71b8b04 commit ea49442
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/doc/guide-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,32 @@ fn succ(x: &int) -> int { *x + 1 }
to

```{rust}
use std::rc::Rc;
fn box_succ(x: Box<int>) -> int { *x + 1 }
fn rc_succ(x: std::rc::Rc<int>) -> int { *x + 1 }
fn rc_succ(x: Rc<int>) -> int { *x + 1 }
```

Note that the caller of your function will have to modify their calls slightly:

```{rust}
use std::rc::Rc;
fn succ(x: &int) -> int { *x + 1 }
let ref_x = &5i;
let box_x = box 5i;
let rc_x = Rc::new(5i);
succ(ref_x);
succ(&*box_x);
succ(&*rc_x);
```

The initial `*` dereferences the pointer, and then `&` takes a reference to
those contents.

# Boxes

`Box<T>` is Rust's 'boxed pointer' type. Boxes provide the simplest form of
Expand Down

0 comments on commit ea49442

Please sign in to comment.