ArrayStorage

Struct ArrayStorage 

Source
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>

Source

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>

Source

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]));
Source

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)
Source

pub fn len(&self) -> usize

Returns the number of non-empty iterators stored in ArrayStorage

Source

pub const fn capacity(&self) -> usize

Returns the (fixed) capacity of ArrayStorage

Source

pub fn is_empty(&self) -> bool

Returns true if this ArrayStorage is empty

Source

pub fn push<Iter>(&mut self, iter: Iter)
where Iter: IntoIterator<IntoIter = IT>,

Appends an element to the back of a collection.

§Panics

Panics if the collection is full.

Source

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

Source

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();
Source

pub fn build( self: Pin<&mut Self>, ) -> DefaultMergeIter<InternalArrayStorage<'_, IT>>
where IT::Item: Ord,

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> Debug for ArrayStorage<CAP, IT>
where PeekIter<IT>: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const CAP: usize, IT: Iterator> Default for ArrayStorage<CAP, IT>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const CAP: usize, IT: Iterator> Drop for ArrayStorage<CAP, IT>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<const CAP: usize, IT, Item> FromIterator<Item> for ArrayStorage<CAP, IT>
where IT: Iterator, Item: IntoIterator<IntoIter = IT>,

Source§

fn from_iter<T: IntoIterator<Item = Item>>(iter: T) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<const CAP: usize, IT> !Freeze for ArrayStorage<CAP, IT>

§

impl<const CAP: usize, IT> !RefUnwindSafe for ArrayStorage<CAP, IT>

§

impl<const CAP: usize, IT> !Send for ArrayStorage<CAP, IT>

§

impl<const CAP: usize, IT> !Sync for ArrayStorage<CAP, IT>

§

impl<const CAP: usize, IT> !Unpin for ArrayStorage<CAP, IT>

§

impl<const CAP: usize, IT> UnwindSafe for ArrayStorage<CAP, IT>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.