diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-11-26 09:44:51 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-11-26 16:49:49 -0800 |
| commit | ea4944233e192f40ddcaae6cf932dab65b98afdf (patch) | |
| tree | f9d977aec08c2c7ac12aff5116df592e2e1aea2f /src | |
| parent | 69e7554a479fc186ee0ef0de2e4c1d9b3300317c (diff) | |
| parent | 71b8b04f48a3c596a50d78405eb5b0eea80ad8e6 (diff) | |
| download | rust-ea4944233e192f40ddcaae6cf932dab65b98afdf.tar.gz rust-ea4944233e192f40ddcaae6cf932dab65b98afdf.zip | |
rollup merge of #19304: steveklabnik/gh19302
Fixes #19302. Also made a minor cosmetic change to bring the example in line with style guidelines.
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/guide-pointers.md | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/doc/guide-pointers.md b/src/doc/guide-pointers.md index cf7ecd7e51f..64b440259cf 100644 --- a/src/doc/guide-pointers.md +++ b/src/doc/guide-pointers.md @@ -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 |
