From 8d10f965f4400e5d01c944b331285b8ea1488788 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 24 Sep 2018 21:55:54 -0400 Subject: [PATCH] Indicate how to move value out of Box in docs. Fixes https://github.com/rust-lang/rust/issues/53634. --- src/liballoc/boxed.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index d4cca387f0689..f989e701913a5 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 = Box::new(val); +//! ``` +//! +//! Move a value from a [`Box`] back to the stack by [dereferencing]: +//! +//! ``` +//! let boxed: Box = 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")]