diff options
| author | kennytm <kennytm@gmail.com> | 2018-10-01 16:12:58 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-01 16:12:58 +0800 |
| commit | 4941670cb865b5bbf90751fdc12d1a43c0a628be (patch) | |
| tree | 972ebab86e9dab7dd1ca64760720855a58726545 /src/liballoc | |
| parent | b18821201f526a66617558f33c63854ab67a87f7 (diff) | |
| parent | 8d10f965f4400e5d01c944b331285b8ea1488788 (diff) | |
| download | rust-4941670cb865b5bbf90751fdc12d1a43c0a628be.tar.gz rust-4941670cb865b5bbf90751fdc12d1a43c0a628be.zip | |
Rollup merge of #54544 - frewsxcv:frewsxcv-deref, r=GuillaumeGomez
Indicate how to move value out of Box in docs. Fixes https://github.com/rust-lang/rust/issues/53634.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index d4cca387f06..f989e701913 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -16,10 +16,18 @@ //! //! # Examples //! -//! Creating a box: +//! Move a value from the stack to the heap by creating a [`Box`]: //! //! ``` -//! let x = Box::new(5); +//! let val: u8 = 5; +//! let boxed: Box<u8> = Box::new(val); +//! ``` +//! +//! Move a value from a [`Box`] back to the stack by [dereferencing]: +//! +//! ``` +//! let boxed: Box<u8> = Box::new(5); +//! let val: u8 = *boxed; //! ``` //! //! Creating a recursive data structure: @@ -52,6 +60,9 @@ //! elements are in the list, and so we don't know how much memory to allocate //! for a `Cons`. By introducing a `Box`, which has a defined size, we know how //! big `Cons` needs to be. +//! +//! [dereferencing]: ../../std/ops/trait.Deref.html +//! [`Box`]: struct.Box.html #![stable(feature = "rust1", since = "1.0.0")] |
