From 6233f3f4a391b9ef562e77dc4fb857ffaa4ca410 Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Sat, 20 Feb 2021 15:22:48 +0200 Subject: alloc: Added `as_slice` method to `BinaryHeap` collection --- library/alloc/src/collections/binary_heap.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'library/alloc/src/collections') 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 BinaryHeap { 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. /// -- cgit 1.4.1-3-g733a5