|
1 | 1 | //! A pointer type for heap allocation. |
2 | 2 | //! |
3 | | -//! `Box<T>`, casually referred to as a 'box', provides the simplest form of |
| 3 | +//! [`Box<T>`], casually referred to as a 'box', provides the simplest form of |
4 | 4 | //! heap allocation in Rust. Boxes provide ownership for this allocation, and |
5 | 5 | //! drop their contents when they go out of scope. |
6 | 6 | //! |
|
48 | 48 | //! |
49 | 49 | //! It wouldn't work. This is because the size of a `List` depends on how many |
50 | 50 | //! elements are in the list, and so we don't know how much memory to allocate |
51 | | -//! for a `Cons`. By introducing a `Box`, which has a defined size, we know how |
| 51 | +//! for a `Cons`. By introducing a [`Box<T>`], which has a defined size, we know how |
52 | 52 | //! big `Cons` needs to be. |
53 | 53 | //! |
54 | 54 | //! # Memory layout |
|
59 | 59 | //! [`Layout`] used with the allocator is correct for the type. More precisely, |
60 | 60 | //! a `value: *mut T` that has been allocated with the [`Global`] allocator |
61 | 61 | //! with `Layout::for_value(&*value)` may be converted into a box using |
62 | | -//! `Box::<T>::from_raw(value)`. Conversely, the memory backing a `value: *mut |
63 | | -//! T` obtained from `Box::<T>::into_raw` may be deallocated using the |
64 | | -//! [`Global`] allocator with `Layout::for_value(&*value)`. |
| 62 | +//! [`Box::<T>::from_raw(value)`]. Conversely, the memory backing a `value: *mut |
| 63 | +//! T` obtained from [`Box::<T>::into_raw`] may be deallocated using the |
| 64 | +//! [`Global`] allocator with [`Layout::for_value(&*value)`]. |
65 | 65 | //! |
66 | 66 | //! |
67 | 67 | //! [dereferencing]: ../../std/ops/trait.Deref.html |
68 | 68 | //! [`Box`]: struct.Box.html |
| 69 | +//! [`Box<T>`]: struct.Box.html |
| 70 | +//! [`Box::<T>::from_raw(value)`]: struct.Box.html#method.from_raw |
| 71 | +//! [`Box::<T>::into_raw`]: struct.Box.html#method.into_raw |
69 | 72 | //! [`Global`]: ../alloc/struct.Global.html |
70 | 73 | //! [`Layout`]: ../alloc/struct.Layout.html |
| 74 | +//! [`Layout::for_value(&*value)`]: ../alloc/struct.Layout.html#method.for_value |
71 | 75 |
|
72 | 76 | #![stable(feature = "rust1", since = "1.0.0")] |
73 | 77 |
|
|
0 commit comments