Skip to content

Commit ea49442

Browse files
committed
rollup merge of rust-lang#19304: steveklabnik/gh19302
Fixes rust-lang#19302. Also made a minor cosmetic change to bring the example in line with style guidelines.
2 parents 69e7554 + 71b8b04 commit ea49442

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/doc/guide-pointers.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,32 @@ fn succ(x: &int) -> int { *x + 1 }
445445
to
446446

447447
```{rust}
448+
use std::rc::Rc;
449+
448450
fn box_succ(x: Box<int>) -> int { *x + 1 }
449451
450-
fn rc_succ(x: std::rc::Rc<int>) -> int { *x + 1 }
452+
fn rc_succ(x: Rc<int>) -> int { *x + 1 }
453+
```
454+
455+
Note that the caller of your function will have to modify their calls slightly:
456+
457+
```{rust}
458+
use std::rc::Rc;
459+
460+
fn succ(x: &int) -> int { *x + 1 }
461+
462+
let ref_x = &5i;
463+
let box_x = box 5i;
464+
let rc_x = Rc::new(5i);
465+
466+
succ(ref_x);
467+
succ(&*box_x);
468+
succ(&*rc_x);
451469
```
452470

471+
The initial `*` dereferences the pointer, and then `&` takes a reference to
472+
those contents.
473+
453474
# Boxes
454475

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

0 commit comments

Comments
 (0)