File tree 1 file changed +22
-1
lines changed
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 }
445
445
to
446
446
447
447
``` {rust}
448
+ use std::rc::Rc;
449
+
448
450
fn box_succ(x: Box<int>) -> int { *x + 1 }
449
451
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);
451
469
```
452
470
471
+ The initial ` * ` dereferences the pointer, and then ` & ` takes a reference to
472
+ those contents.
473
+
453
474
# Boxes
454
475
455
476
` 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