Skip to content

Commit 4941670

Browse files
authored
Rollup merge of rust-lang#54544 - frewsxcv:frewsxcv-deref, r=GuillaumeGomez
Indicate how to move value out of Box in docs. Fixes rust-lang#53634.
2 parents b188212 + 8d10f96 commit 4941670

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/liballoc/boxed.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@
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:
@@ -52,6 +60,9 @@
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

0 commit comments

Comments
 (0)