diff options
| author | Vlad Frolov <frolvlad@gmail.com> | 2021-02-20 15:22:48 +0200 |
|---|---|---|
| committer | Vlad Frolov <frolvlad@gmail.com> | 2021-02-20 20:46:16 +0200 |
| commit | 6233f3f4a391b9ef562e77dc4fb857ffaa4ca410 (patch) | |
| tree | f73713bcee7f4a853a37e62fe483b56706252eb3 /library/alloc/src/collections | |
| parent | da5f7f10936198bad22c370118bad1ac332d2f46 (diff) | |
| download | rust-6233f3f4a391b9ef562e77dc4fb857ffaa4ca410.tar.gz rust-6233f3f4a391b9ef562e77dc4fb857ffaa4ca410.zip | |
alloc: Added `as_slice` method to `BinaryHeap` collection
Diffstat (limited to 'library/alloc/src/collections')
| -rw-r--r-- | library/alloc/src/collections/binary_heap.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 8a36b2af765..7a43a3a868b 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -889,6 +889,29 @@ impl<T> BinaryHeap<T> { self.data.shrink_to(min_capacity) } + /// Returns a slice of all values in the underlying vector, in arbitrary + /// order. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(binary_heap_as_slice)] + /// use std::collections::BinaryHeap; + /// let heap = BinaryHeap::from(vec![1, 2, 3, 4, 5, 6, 7]); + /// let slice = heap.as_slice(); + /// + /// // Will print in some order + /// for x in slice { + /// println!("{}", x); + /// } + /// ``` + #[unstable(feature = "binary_heap_as_slice", issue = "82331")] + pub fn as_slice(&self) -> &[T] { + self.data.as_slice() + } + /// Consumes the `BinaryHeap` and returns the underlying vector /// in arbitrary order. /// |
