pub struct ArrayStorage<const CAP: usize, IT: Iterator> { /* private fields */ }Expand description
Fixed-capacity array-based storage for MergeIter
Implementations§
Source§impl<IT: Iterator> ArrayStorage<0, IT>
impl<IT: Iterator> ArrayStorage<0, IT>
Sourcepub const fn with_capacity<const CAP: usize>() -> ArrayStorage<CAP, IT>
pub const fn with_capacity<const CAP: usize>() -> ArrayStorage<CAP, IT>
Create ArrayStorage with given capacity and inferred iterator type
Source§impl<const CAP: usize, IT: Iterator> ArrayStorage<CAP, IT>
impl<const CAP: usize, IT: Iterator> ArrayStorage<CAP, IT>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new ArrayStorage
§Example
Building a merge iterator from an ArrayStorage.
use core::{iter, pin::pin};
use iter_merge::ArrayStorage;
let mut storage: ArrayStorage<5, _> = ArrayStorage::new();
storage.push(iter::once(2));
storage.push(iter::once(1));
let storage = pin!(storage);
let it = storage.build();
assert!(it.eq([1, 2]));Sourcepub fn from_arr<T: IntoIterator<IntoIter = IT>>(iters: [T; CAP]) -> Self
pub fn from_arr<T: IntoIterator<IntoIter = IT>>(iters: [T; CAP]) -> Self
Creates a new ArrayStorage with the same CAP as
the provided array.
§Example
Building a merge iterator from an ArrayStorage.
use core::{iter, pin::pin};
use iter_merge::ArrayStorage;
let storage = ArrayStorage::from_arr([[1, 3], [2, 4]]);
assert_eq!(storage.capacity(), 2)Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of non-empty iterators stored in ArrayStorage
Sourcepub const fn capacity(&self) -> usize
pub const fn capacity(&self) -> usize
Returns the (fixed) capacity of ArrayStorage
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this ArrayStorage is empty
Sourcepub fn push<Iter>(&mut self, iter: Iter)where
Iter: IntoIterator<IntoIter = IT>,
pub fn push<Iter>(&mut self, iter: Iter)where
Iter: IntoIterator<IntoIter = IT>,
Sourcepub fn try_push<Iter>(
&mut self,
iter: Iter,
) -> Result<(), ArrayCapacityOverflow>where
Iter: IntoIterator<IntoIter = IT>,
pub fn try_push<Iter>(
&mut self,
iter: Iter,
) -> Result<(), ArrayCapacityOverflow>where
Iter: IntoIterator<IntoIter = IT>,
Tries to append an element to the back of a collection.
§Errors
Returns error if the ArrayStorage is full
Sourcepub fn into_builder(
self: Pin<&mut Self>,
) -> DefaultBuilder<InternalArrayStorage<'_, IT>>
pub fn into_builder( self: Pin<&mut Self>, ) -> DefaultBuilder<InternalArrayStorage<'_, IT>>
Constructs a [Builder] from this storage.
Note: the storage cannot move for MergeIter to work, thus
you need to call this method on a pinned mutable reference.
Example:
use core::{iter, pin::pin};
use iter_merge::ArrayStorage;
let mut storage = ArrayStorage::<5, _>::new();
storage.push(iter::once(1));
let storage = pin!(storage);
let _builder = storage.into_builder();Sourcepub fn build(
self: Pin<&mut Self>,
) -> DefaultMergeIter<InternalArrayStorage<'_, IT>>
pub fn build( self: Pin<&mut Self>, ) -> DefaultMergeIter<InternalArrayStorage<'_, IT>>
Constructs a [MergeIter] from this storage with default parameters.
Equivalent to calling Self::into_builder().build()
Trait Implementations§
Source§impl<const CAP: usize, IT: Iterator, A> Extend<A> for ArrayStorage<CAP, IT>where
A: IntoIterator<IntoIter = IT>,
impl<const CAP: usize, IT: Iterator, A> Extend<A> for ArrayStorage<CAP, IT>where
A: IntoIterator<IntoIter = IT>,
Source§fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)