File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 1616//!
1717//! # Examples
1818//!
19- //! Creating a box :
19+ //! Move a value from the stack to the heap by creating a [`Box`] :
2020//!
2121//! ```
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;
2331//! ```
2432//!
2533//! Creating a recursive data structure:
5260//! elements are in the list, and so we don't know how much memory to allocate
5361//! for a `Cons`. By introducing a `Box`, which has a defined size, we know how
5462//! big `Cons` needs to be.
63+ //!
64+ //! [dereferencing]: ../../std/ops/trait.Deref.html
65+ //! [`Box`]: struct.Box.html
5566
5667#![ stable( feature = "rust1" , since = "1.0.0" ) ]
5768
You can’t perform that action at this time.
0 commit comments