From e0e355dd253b46380f975acd33b43302ac470236 Mon Sep 17 00:00:00 2001 From: yanchith Date: Sun, 11 Jun 2023 22:56:16 +0200 Subject: [PATCH] Impl allocator function for iterators --- .../alloc/src/collections/binary_heap/mod.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 93e799410d3..66573b90db9 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -1492,6 +1492,14 @@ pub struct IntoIter< iter: vec::IntoIter, } +impl IntoIter { + /// 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 fmt::Debug for IntoIter { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -1581,6 +1589,14 @@ pub struct IntoIterSorted< inner: BinaryHeap, } +impl IntoIterSorted { + /// 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 Iterator for IntoIterSorted { type Item = T; @@ -1622,6 +1638,14 @@ pub struct Drain< iter: vec::Drain<'a, T, A>, } +impl 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 Iterator for Drain<'_, T, A> { type Item = T; @@ -1671,6 +1695,14 @@ pub struct DrainSorted< inner: &'a mut BinaryHeap, } +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.