Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alloc: Added as_slice method to BinaryHeap collection #82331

Merged
merged 3 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,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.
///
Expand Down
1 change: 1 addition & 0 deletions library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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(int_bits_const)]
Expand Down