mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Rollup merge of #82331 - frol:feat/std-binary-heap-as-slice, r=Amanieu
alloc: Added `as_slice` method to `BinaryHeap` collection I initially asked about whether it is useful addition on https://internals.rust-lang.org/t/should-i-add-as-slice-method-to-binaryheap/13816, and it seems there were no objections, so went ahead with this PR. > There is [`BinaryHeap::into_vec`](https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.into_vec), but it consumes the value. I wonder if there is API design limitation that should be taken into account. Implementation-wise, the inner buffer is just a Vec, so it is trivial to expose as_slice from it. Please, guide me through if I need to add tests or something else. UPD: Tracking issue #83659
This commit is contained in:
commit
2843baaeb6
@ -958,6 +958,27 @@ 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;
|
||||
/// use std::io::{self, Write};
|
||||
///
|
||||
/// let heap = BinaryHeap::from(vec![1, 2, 3, 4, 5, 6, 7]);
|
||||
///
|
||||
/// io::sink().write(heap.as_slice()).unwrap();
|
||||
/// ```
|
||||
#[unstable(feature = "binary_heap_as_slice", issue = "83659")]
|
||||
pub fn as_slice(&self) -> &[T] {
|
||||
self.data.as_slice()
|
||||
}
|
||||
|
||||
/// Consumes the `BinaryHeap` and returns the underlying vector
|
||||
/// in arbitrary order.
|
||||
///
|
||||
|
@ -14,6 +14,7 @@
|
||||
#![feature(binary_heap_drain_sorted)]
|
||||
#![feature(slice_ptr_get)]
|
||||
#![feature(binary_heap_retain)]
|
||||
#![feature(binary_heap_as_slice)]
|
||||
#![feature(inplace_iteration)]
|
||||
#![feature(iter_map_while)]
|
||||
#![feature(vecdeque_binary_search)]
|
||||
|
Loading…
Reference in New Issue
Block a user