File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 16
16
//!
17
17
//! # Examples
18
18
//!
19
- //! Creating a box :
19
+ //! Move a value from the stack to the heap by creating a [`Box`] :
20
20
//!
21
21
//! ```
22
- //! let x = Box::new(5);
22
+ //! let val: u8 = 5;
23
+ //! let boxed: Box<u8> = Box::new(val);
24
+ //! ```
25
+ //!
26
+ //! Move a value from a [`Box`] back to the stack by [dereferencing]:
27
+ //!
28
+ //! ```
29
+ //! let boxed: Box<u8> = Box::new(5);
30
+ //! let val: u8 = *boxed;
23
31
//! ```
24
32
//!
25
33
//! Creating a recursive data structure:
52
60
//! elements are in the list, and so we don't know how much memory to allocate
53
61
//! for a `Cons`. By introducing a `Box`, which has a defined size, we know how
54
62
//! big `Cons` needs to be.
63
+ //!
64
+ //! [dereferencing]: ../../std/ops/trait.Deref.html
65
+ //! [`Box`]: struct.Box.html
55
66
56
67
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
57
68
You can’t perform that action at this time.
0 commit comments