about summary refs log tree commit diff
path: root/library/alloc/src/collections
diff options
context:
space:
mode:
authoryanchith <yanchi.toth@gmail.com>2023-06-11 22:56:16 +0200
committeryanchith <yanchi.toth@gmail.com>2023-06-11 22:56:16 +0200
commite0e355dd253b46380f975acd33b43302ac470236 (patch)
tree31382513a8909b04f6d361268141cdd0db628db6 /library/alloc/src/collections
parentd9b6181d2f04fa1d444b853eca6dd3fb9e0009ed (diff)
downloadrust-e0e355dd253b46380f975acd33b43302ac470236.tar.gz
rust-e0e355dd253b46380f975acd33b43302ac470236.zip
Impl allocator function for iterators
Diffstat (limited to 'library/alloc/src/collections')
-rw-r--r--library/alloc/src/collections/binary_heap/mod.rs32
1 files changed, 32 insertions, 0 deletions
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<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 {
@@ -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;
@@ -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;
@@ -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.