]> git.lizzy.rs Git - rust.git/commitdiff
Indicate how to move value out of Box in docs.
authorCorey Farwell <coreyf@rwell.org>
Tue, 25 Sep 2018 01:55:54 +0000 (21:55 -0400)
committerCorey Farwell <coreyf@rwell.org>
Sat, 29 Sep 2018 02:41:13 +0000 (22:41 -0400)
Fixes https://github.com/rust-lang/rust/issues/53634.

src/liballoc/boxed.rs

index d4cca387f0689ae43135f7c678a7e3580ef001d9..f989e701913a573750578d0a32bab6a6598f60fc 100644 (file)
 //!
 //! # 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")]