Impl allocator function for iterators

This commit is contained in:
yanchith 2023-06-11 22:56:16 +02:00
parent d9b6181d2f
commit e0e355dd25

View File

@ -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.