|
10 | 10 |
|
11 | 11 | //! A pointer type for heap allocation.
|
12 | 12 | //!
|
13 |
| -//! `Box<T>`, casually referred to as a 'box', provides the simplest form of heap allocation in |
14 |
| -//! Rust. Boxes provide ownership for this allocation, and drop their contents when they go out of |
15 |
| -//! scope. |
| 13 | +//! `Box<T>`, casually referred to as a 'box', provides the simplest form of |
| 14 | +//! heap allocation in Rust. Boxes provide ownership for this allocation, and |
| 15 | +//! drop their contents when they go out of scope. |
16 | 16 | //!
|
17 |
| -//! Boxes are useful in two situations: recursive data structures, and occasionally when returning |
18 |
| -//! data. [The Pointer chapter of the Book](../../../book/pointers.html#best-practices-1) explains |
19 |
| -//! these cases in detail. |
| 17 | +//! Boxes are useful in two situations: recursive data structures, and |
| 18 | +//! occasionally when returning data. [The Pointer chapter of the |
| 19 | +//! Book](../../../book/pointers.html#best-practices-1) explains these cases in |
| 20 | +//! detail. |
20 | 21 | //!
|
21 | 22 | //! # Examples
|
22 | 23 | //!
|
@@ -58,8 +59,8 @@ use core::ops::{Deref, DerefMut};
|
58 | 59 | use core::ptr::Unique;
|
59 | 60 | use core::raw::TraitObject;
|
60 | 61 |
|
61 |
| -/// A value that represents the heap. This is the default place that the `box` keyword allocates |
62 |
| -/// into when no place is supplied. |
| 62 | +/// A value that represents the heap. This is the default place that the `box` |
| 63 | +/// keyword allocates into when no place is supplied. |
63 | 64 | ///
|
64 | 65 | /// The following two examples are equivalent:
|
65 | 66 | ///
|
@@ -219,12 +220,20 @@ impl<T: ?Sized + Ord> Ord for Box<T> {
|
219 | 220 | #[stable(feature = "rust1", since = "1.0.0")]
|
220 | 221 | impl<T: ?Sized + Eq> Eq for Box<T> {}
|
221 | 222 |
|
| 223 | +#[cfg(stage0)] |
222 | 224 | impl<S: hash::Hasher, T: ?Sized + Hash<S>> Hash<S> for Box<T> {
|
223 | 225 | #[inline]
|
224 | 226 | fn hash(&self, state: &mut S) {
|
225 | 227 | (**self).hash(state);
|
226 | 228 | }
|
227 | 229 | }
|
| 230 | +#[cfg(not(stage0))] |
| 231 | +#[stable(feature = "rust1", since = "1.0.0")] |
| 232 | +impl<T: ?Sized + Hash> Hash for Box<T> { |
| 233 | + fn hash<H: hash::Hasher>(&self, state: &mut H) { |
| 234 | + (**self).hash(state); |
| 235 | + } |
| 236 | +} |
228 | 237 |
|
229 | 238 | /// Extension methods for an owning `Any` trait object.
|
230 | 239 | #[unstable(feature = "alloc",
|
|
0 commit comments