Skip to content

Commit

Permalink
Impl allocator function for iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
yanchith committed Jun 11, 2023
1 parent d9b6181 commit e0e355d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions library/alloc/src/collections/binary_heap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,14 @@ pub struct IntoIter<
iter: vec::IntoIter<T, A>,
}

impl<T, A: Allocator> IntoIter<T, A> {
/// Returns a reference to the underlying allocator.
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(&self) -> &A {
self.iter.allocator()
}
}

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<T: fmt::Debug, A: Allocator> fmt::Debug for IntoIter<T, A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -1581,6 +1589,14 @@ pub struct IntoIterSorted<
inner: BinaryHeap<T, A>,
}

impl<T, A: Allocator> IntoIterSorted<T, A> {
/// Returns a reference to the underlying allocator.
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(&self) -> &A {
self.inner.allocator()
}
}

#[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
impl<T: Ord, A: Allocator> Iterator for IntoIterSorted<T, A> {
type Item = T;
Expand Down Expand Up @@ -1622,6 +1638,14 @@ pub struct Drain<
iter: vec::Drain<'a, T, A>,
}

impl<T, A: Allocator> Drain<'_, T, A> {
/// Returns a reference to the underlying allocator.
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(&self) -> &A {
self.iter.allocator()
}
}

#[stable(feature = "drain", since = "1.6.0")]
impl<T, A: Allocator> Iterator for Drain<'_, T, A> {
type Item = T;
Expand Down Expand Up @@ -1671,6 +1695,14 @@ pub struct DrainSorted<
inner: &'a mut BinaryHeap<T, A>,
}

impl<'a, T: Ord, A: Allocator> DrainSorted<'a, T, A> {
/// Returns a reference to the underlying allocator.
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(&self) -> &A {
self.inner.allocator()
}
}

#[unstable(feature = "binary_heap_drain_sorted", issue = "59278")]
impl<'a, T: Ord, A: Allocator> Drop for DrainSorted<'a, T, A> {
/// Removes heap elements in heap order.
Expand Down

0 comments on commit e0e355d

Please sign in to comment.