File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -445,11 +445,32 @@ fn succ(x: &int) -> int { *x + 1 }
445445to
446446
447447``` {rust}
448+ use std::rc::Rc;
449+
448450fn 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
You can’t perform that action at this time.
0 commit comments