NonEmptyIterator

Trait NonEmptyIterator 

Source
pub unsafe trait NonEmptyIterator: IntoIterator + Sized {
Show 60 methods // Provided methods fn consume(self) -> (Self::Item, Self::IntoIter) { ... } fn count(self) -> Size { ... } fn enumerate(self) -> Enumerate<Self> { ... } fn peeked(self) -> Peeked<Self::IntoIter> { ... } fn chain<I: IntoIterator<Item = Self::Item>>( self, other: I, ) -> Chain<Self, I::IntoIter> { ... } fn cloned<'a, T>(self) -> Cloned<Self> where Self: NonEmptyIterator<Item = &'a T>, T: Clone + 'a { ... } fn copied<'a, T>(self) -> Copied<Self> where Self: NonEmptyIterator<Item = &'a T>, T: Copy + 'a { ... } fn zip<I: IntoNonEmptyIterator>( self, other: I, ) -> Zip<Self, I::IntoNonEmptyIter> { ... } fn sum<S: Sum<Self::Item>>(self) -> S { ... } fn product<P: Product<Self::Item>>(self) -> P { ... } fn all<P: FnMut(Self::Item) -> bool>(self, predicate: P) -> bool { ... } fn any<P: FnMut(Self::Item) -> bool>(self, predicate: P) -> bool { ... } fn none<P: FnMut(Self::Item) -> bool>(self, predicate: P) -> bool { ... } fn reduce<F>(self, function: F) -> Self::Item where F: FnMut(Self::Item, Self::Item) -> Self::Item { ... } fn unzip<T, U, C: Default + Extend<T>, D: Default + Extend<U>>( self, ) -> (C, D) where Self: NonEmptyIterator<Item = (T, U)> { ... } fn collect<C: FromIterator<Self::Item>>(self) -> C { ... } fn collect_non_empty<C: FromNonEmptyIterator<Self::Item>>(self) -> C { ... } fn flat_map<J: IntoNonEmptyIterator, F: FnMut(Self::Item) -> J>( self, function: F, ) -> FlatMap<Self, J, F> { ... } fn flatten(self) -> Flatten<Self> where Self::Item: IntoNonEmptyIterator { ... } fn filter<P: FnMut(&Self::Item) -> bool>( self, predicate: P, ) -> Filter<Self::IntoIter, P> { ... } fn find<P: FnMut(&Self::Item) -> bool>( self, predicate: P, ) -> Option<Self::Item> { ... } fn filter_map<T, F: FnMut(Self::Item) -> Option<T>>( self, function: F, ) -> FilterMap<Self::IntoIter, F> { ... } fn fold<A, F: FnMut(A, Self::Item) -> A>(self, initial: A, function: F) -> A { ... } fn map<U, F: FnMut(Self::Item) -> U>(self, function: F) -> Map<Self, F> { ... } fn max(self) -> Self::Item where Self::Item: Ord { ... } fn max_by<F: FnMut(&Self::Item, &Self::Item) -> Ordering>( self, function: F, ) -> Self::Item { ... } fn max_by_key<K: Ord, F: FnMut(&Self::Item) -> K>( self, function: F, ) -> Self::Item { ... } fn min(self) -> Self::Item where Self::Item: Ord { ... } fn min_by<F: FnMut(&Self::Item, &Self::Item) -> Ordering>( self, function: F, ) -> Self::Item { ... } fn min_by_key<K: Ord, F: FnMut(&Self::Item) -> K>( self, function: F, ) -> Self::Item { ... } fn nth(self, n: Size) -> Option<Self::Item> { ... } fn skip(self, count: Size) -> Skip<Self::IntoIter> { ... } fn take(self, count: Size) -> Take<Self> { ... } fn last(self) -> Self::Item { ... } fn step_by(self, step: Size) -> StepBy<Self> { ... } fn for_each<F: FnMut(Self::Item)>(self, function: F) { ... } fn exhaust(self) { ... } fn skip_while<P: FnMut(&Self::Item) -> bool>( self, predicate: P, ) -> SkipWhile<Self::IntoIter, P> { ... } fn take_while<P: FnMut(&Self::Item) -> bool>( self, predicate: P, ) -> TakeWhile<Self::IntoIter, P> { ... } fn map_while<T, P: FnMut(Self::Item) -> Option<T>>( self, predicate: P, ) -> MapWhile<Self::IntoIter, P> { ... } fn scan<S, T, F: FnMut(&mut S, Self::Item) -> Option<T>>( self, initial: S, function: F, ) -> Scan<Self::IntoIter, S, F> { ... } fn inspect<F: FnMut(&Self::Item)>(self, function: F) -> Inspect<Self, F> { ... } fn partition<C: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool>( self, function: F, ) -> (C, C) { ... } fn position<P: FnMut(Self::Item) -> bool>( self, predicate: P, ) -> Option<usize> { ... } fn cmp<I: IntoIterator<Item = Self::Item>>(self, other: I) -> Ordering where Self::Item: Ord { ... } fn partial_cmp<I: IntoIterator>(self, other: I) -> Option<Ordering> where Self::Item: PartialOrd<I::Item> { ... } fn eq<I: IntoIterator>(self, other: I) -> bool where Self::Item: PartialEq<I::Item> { ... } fn ne<I: IntoIterator>(self, other: I) -> bool where Self::Item: PartialEq<I::Item> { ... } fn lt<I: IntoIterator>(self, other: I) -> bool where Self::Item: PartialOrd<I::Item> { ... } fn le<I: IntoIterator>(self, other: I) -> bool where Self::Item: PartialOrd<I::Item> { ... } fn gt<I: IntoIterator>(self, other: I) -> bool where Self::Item: PartialOrd<I::Item> { ... } fn ge<I: IntoIterator>(self, other: I) -> bool where Self::Item: PartialOrd<I::Item> { ... } fn is_sorted(self) -> bool where Self::Item: PartialOrd { ... } fn is_sorted_by<F: FnMut(&Self::Item, &Self::Item) -> bool>( self, function: F, ) -> bool { ... } fn is_sorted_by_key<K: PartialOrd, F: FnMut(Self::Item) -> K>( self, function: F, ) -> bool { ... } fn collect_into<C: Extend<Self::Item>>(self, collection: &mut C) -> &mut C { ... } fn find_map<T, F: FnMut(Self::Item) -> Option<T>>( self, function: F, ) -> Option<T> { ... } fn fuse(self) -> Fuse<Self> { ... } fn rev(self) -> Rev<Self> where Self::IntoIter: DoubleEndedIterator { ... } fn cycle(self) -> Cycle<Self> where Self::IntoIter: Clone { ... }
}
Expand description

Represents Iterator that is guaranteed to be non-empty (equivalently, having at least one item).

Note that this trait is unsafe to implement, as the implementor must guarantee non-emptiness.

Moreover, NonEmptyIterator has IntoIterator and Sized bounds, as it is always consumed by value and converted into the underlying iterator.

One can use the for loop with non-empty iterators, and downgrade to the regular Iterator by calling into_iter or consume.

§Safety

By implementing NonEmptyIterator the implementor is responsible for ensuring that non-emptiness holds. Violating this invariant causes Undefined Behavior!

Provided Methods§

Source

fn consume(self) -> (Self::Item, Self::IntoIter)

Consumes the non-empty iterator, returning the next item along with the possibly empty iterator.

Source

fn count(self) -> Size

Consumes the non-empty iterator, returning the item count.

See also count on Iterator.

§Non-zero

The returned count is guaranteed to be non-zero.

Source

fn enumerate(self) -> Enumerate<Self>

Creates non-empty iterators that yield the current count and the item during iteration.

See also enumerate on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn peeked(self) -> Peeked<Self::IntoIter>

Peeks at the next item of the non-empty iterator, returning it along with the possibly empty iterator.

This is equivalent to calling consume and wrapping the output.

See also peekable on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn chain<I: IntoIterator<Item = Self::Item>>( self, other: I, ) -> Chain<Self, I::IntoIter>

Links the non-empty iterator with the provided possibly empty iterator.

See also chain on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn cloned<'a, T>(self) -> Cloned<Self>
where Self: NonEmptyIterator<Item = &'a T>, T: Clone + 'a,

Creates non-empty iterators that clone the items of the underlying non-empty iterator.

See also cloned on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn copied<'a, T>(self) -> Copied<Self>
where Self: NonEmptyIterator<Item = &'a T>, T: Copy + 'a,

Creates non-empty iterators that copy the items of the underlying non-empty iterator.

See also copied on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn zip<I: IntoNonEmptyIterator>( self, other: I, ) -> Zip<Self, I::IntoNonEmptyIter>

Zips the non-empty iterator with the provided non-empty iterator.

This allows to iterate over the items of both iterators simultaneously.

See also zip on Iterator.

§Difference from Iterator

Note that the argument is required to be IntoNonEmptyIterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn sum<S: Sum<Self::Item>>(self) -> S

Sums the items of the non-empty iterator together.

See also sum on Iterator.

Source

fn product<P: Product<Self::Item>>(self) -> P

Multiplies the items of the non-empty iterator together.

See also product on Iterator.

Source

fn all<P: FnMut(Self::Item) -> bool>(self, predicate: P) -> bool

Tests whether all items of the non-empty iterator match the predicate.

See also all on Iterator.

Source

fn any<P: FnMut(Self::Item) -> bool>(self, predicate: P) -> bool

Tests whether any items of the non-empty iterator match the predicate.

See also any on Iterator.

Source

fn none<P: FnMut(Self::Item) -> bool>(self, predicate: P) -> bool

Tests whether no items of the non-empty iterator match the predicate.

This is equivalent to negating the output of any.

Source

fn reduce<F>(self, function: F) -> Self::Item
where F: FnMut(Self::Item, Self::Item) -> Self::Item,

Reduces the items of the non-empty iterator into the single one by repeatedly applying the given function.

See also reduce on Iterator.

§Difference from Iterator

Note that this function always returns some value, as the iterator is non-empty.

Source

fn unzip<T, U, C: Default + Extend<T>, D: Default + Extend<U>>(self) -> (C, D)
where Self: NonEmptyIterator<Item = (T, U)>,

Converts the non-empty iterator of pairs into the pair of collections.

See also unzip on Iterator.

Source

fn collect<C: FromIterator<Self::Item>>(self) -> C

Equivalent to collect on Iterator.

See also collect_non_empty.

Source

fn collect_non_empty<C: FromNonEmptyIterator<Self::Item>>(self) -> C

Collects the items of the non-empty iterator into the collection.

See also collect.

§Difference from Iterator

Note that the collection is required to be FromNonEmptyIterator.

Source

fn flat_map<J: IntoNonEmptyIterator, F: FnMut(Self::Item) -> J>( self, function: F, ) -> FlatMap<Self, J, F>

Similar to map, but flattens produced non-empty iterators.

See also flat_map on Iterator.

§Difference from Iterator

Note that the function is required to return IntoNonEmptyIterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn flatten(self) -> Flatten<Self>

Flattens one level of nesting in self non-empty iterator.

See also flatten on Iterator.

§Difference from Iterator

Note that the items are required to be IntoNonEmptyIterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn filter<P: FnMut(&Self::Item) -> bool>( self, predicate: P, ) -> Filter<Self::IntoIter, P>

Equivalent to filter on Iterator.

Note that the returned iterator can be empty, depending on the predicate.

Source

fn find<P: FnMut(&Self::Item) -> bool>(self, predicate: P) -> Option<Self::Item>

Equivalent to find on Iterator.

Source

fn filter_map<T, F: FnMut(Self::Item) -> Option<T>>( self, function: F, ) -> FilterMap<Self::IntoIter, F>

Equivalent to filter_map on Iterator.

Note that the returned iterator can be empty, depending on the function.

Source

fn fold<A, F: FnMut(A, Self::Item) -> A>(self, initial: A, function: F) -> A

Equivalent to fold on Iterator.

Source

fn map<U, F: FnMut(Self::Item) -> U>(self, function: F) -> Map<Self, F>

Creates non-empty iterators that map the items of the non-empty iterator with the function.

See also map on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn max(self) -> Self::Item
where Self::Item: Ord,

Returns the maximum item of the non-empty iterator.

See also max on Iterator.

§Difference from Iterator

Note that this function always returns some value, as the iterator is non-empty.

Source

fn max_by<F: FnMut(&Self::Item, &Self::Item) -> Ordering>( self, function: F, ) -> Self::Item

Returns the maximum item of the non-empty iterator with respect to the comparison function.

See also max_by on Iterator.

§Difference from Iterator

Note that this function always returns some value, as the iterator is non-empty.

Source

fn max_by_key<K: Ord, F: FnMut(&Self::Item) -> K>( self, function: F, ) -> Self::Item

Returns the maximum item of the non-empty iterator with respect to the key function.

See also max_by_key on Iterator.

§Difference from Iterator

Note that this function always returns some value, as the iterator is non-empty.

Source

fn min(self) -> Self::Item
where Self::Item: Ord,

Returns the minimum item of the non-empty iterator.

See also min on Iterator.

§Difference from Iterator

Note that this function always returns some value, as the iterator is non-empty.

Source

fn min_by<F: FnMut(&Self::Item, &Self::Item) -> Ordering>( self, function: F, ) -> Self::Item

Returns the minimum item of the non-empty iterator with respect to the comparison function.

See also min_by on Iterator.

§Difference from Iterator

Note that this function always returns some value, as the iterator is non-empty.

Source

fn min_by_key<K: Ord, F: FnMut(&Self::Item) -> K>( self, function: F, ) -> Self::Item

Returns the minimum item of the non-empty iterator with respect to the key function.

See also min_by_key on Iterator.

§Difference from Iterator

Note that this function always returns some value, as the iterator is non-empty.

Source

fn nth(self, n: Size) -> Option<Self::Item>

Returns the n-th item of the non-empty iterator.

See also nth on Iterator.

§Difference from Iterator

Note that this function expects non-zero n, as the first item can be obtained via consume.

Source

fn skip(self, count: Size) -> Skip<Self::IntoIter>

Skips the first given number of items in the non-empty iterator.

See also skip on Iterator.

The returned iterator can be empty, depending on the count.

§Difference from Iterator

Note that this function expects non-zero count.

Source

fn take(self, count: Size) -> Take<Self>

Takes only the first given number of items from the non-empty iterator.

See also take on Iterator.

§Difference from Iterator

Note that this function expects non-zero count in order to guarantee non-emptiness.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn last(self) -> Self::Item

Returns the last item of the non-empty iterator.

See also last on Iterator.

§Difference from Iterator

Note that this function always returns some value, as the iterator is non-empty.

Source

fn step_by(self, step: Size) -> StepBy<Self>

Steps the non-empty iterator by the given custom amount.

See also step_by on Iterator.

§Difference from Iterator

Note that this function expects non-zero step as the step_by on Iterator panics on zero.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn for_each<F: FnMut(Self::Item)>(self, function: F)

Equivalent to for_each on Iterator.

Source

fn exhaust(self)

Consumes the iterator, exhausting it by dropping all of its items.

This is equivalent to calling for_each with drop.

Source

fn skip_while<P: FnMut(&Self::Item) -> bool>( self, predicate: P, ) -> SkipWhile<Self::IntoIter, P>

Equivalent to skip_while on Iterator.

Note that the returned iterator can be empty, depending on the predicate.

Source

fn take_while<P: FnMut(&Self::Item) -> bool>( self, predicate: P, ) -> TakeWhile<Self::IntoIter, P>

Equivalent to take_while on Iterator.

Note that the returned iterator can be empty, depending on the predicate.

Source

fn map_while<T, P: FnMut(Self::Item) -> Option<T>>( self, predicate: P, ) -> MapWhile<Self::IntoIter, P>

Equivalent to map_while on Iterator.

Note that the returned iterator can be empty, depending on the predicate.

Source

fn scan<S, T, F: FnMut(&mut S, Self::Item) -> Option<T>>( self, initial: S, function: F, ) -> Scan<Self::IntoIter, S, F>

Equivalent to scan on Iterator.

Note that the returned iterator can be empty, depending on the function.

Source

fn inspect<F: FnMut(&Self::Item)>(self, function: F) -> Inspect<Self, F>

Creates non-empty iterators that call the provided function with references to each item.

See also inspect on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn partition<C: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool>( self, function: F, ) -> (C, C)

Equivalent to partition on Iterator.

Source

fn position<P: FnMut(Self::Item) -> bool>(self, predicate: P) -> Option<usize>

Equivalent to position on Iterator.

Source

fn cmp<I: IntoIterator<Item = Self::Item>>(self, other: I) -> Ordering
where Self::Item: Ord,

Equivalent to cmp on Iterator.

Source

fn partial_cmp<I: IntoIterator>(self, other: I) -> Option<Ordering>
where Self::Item: PartialOrd<I::Item>,

Equivalent to partial_cmp on Iterator.

Source

fn eq<I: IntoIterator>(self, other: I) -> bool
where Self::Item: PartialEq<I::Item>,

Equivalent to eq on Iterator.

Source

fn ne<I: IntoIterator>(self, other: I) -> bool
where Self::Item: PartialEq<I::Item>,

Equivalent to ne on Iterator.

Source

fn lt<I: IntoIterator>(self, other: I) -> bool
where Self::Item: PartialOrd<I::Item>,

Equivalent to lt on Iterator.

Source

fn le<I: IntoIterator>(self, other: I) -> bool
where Self::Item: PartialOrd<I::Item>,

Equivalent to le on Iterator.

Source

fn gt<I: IntoIterator>(self, other: I) -> bool
where Self::Item: PartialOrd<I::Item>,

Equivalent to gt on Iterator.

Source

fn ge<I: IntoIterator>(self, other: I) -> bool
where Self::Item: PartialOrd<I::Item>,

Equivalent to ge on Iterator.

Source

fn is_sorted(self) -> bool
where Self::Item: PartialOrd,

Equivalent to is_sorted on Iterator.

Source

fn is_sorted_by<F: FnMut(&Self::Item, &Self::Item) -> bool>( self, function: F, ) -> bool

Equivalent to is_sorted_by on Iterator.

Source

fn is_sorted_by_key<K: PartialOrd, F: FnMut(Self::Item) -> K>( self, function: F, ) -> bool

Equivalent to is_sorted_by_key on Iterator.

Source

fn collect_into<C: Extend<Self::Item>>(self, collection: &mut C) -> &mut C

Similar to collect, but extends the provided collection instead of creating new ones.

Returns the provided collection after extending.

Source

fn find_map<T, F: FnMut(Self::Item) -> Option<T>>( self, function: F, ) -> Option<T>

Equivalent to find_map on Iterator.

Source

fn fuse(self) -> Fuse<Self>

Fuses the non-empty iterator, ensuring that once it returns None, it will return None forever afterwards.

See also fuse on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn rev(self) -> Rev<Self>

Reverses the iteration in non-empty iterators.

See also rev on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Source

fn cycle(self) -> Cycle<Self>
where Self::IntoIter: Clone,

Repeats the non-empty iterator endlessly.

See also cycle on Iterator.

§Non-empty

The returned iterator is guaranteed to be non-empty.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, I, T> NonEmptyIterator for Copied<I>
where I: NonEmptyIterator<Item = &'a T>, T: Copy + 'a,

Source§

impl<'a, I, T> NonEmptyIterator for Cloned<I>
where I: NonEmptyIterator<Item = &'a T>, T: Clone + 'a,

Source§

impl<I: IntoIterator> NonEmptyIterator for NonEmptyAdapter<I>

Source§

impl<I: Iterator> NonEmptyIterator for Peeked<I>

Source§

impl<I: NonEmptyIterator> NonEmptyIterator for Cycle<I>
where I::IntoIter: Clone,

Source§

impl<I: NonEmptyIterator> NonEmptyIterator for Enumerate<I>

Source§

impl<I: NonEmptyIterator> NonEmptyIterator for Flatten<I>

Source§

impl<I: NonEmptyIterator> NonEmptyIterator for Fuse<I>

Source§

impl<I: NonEmptyIterator> NonEmptyIterator for Rev<I>

Source§

impl<I: NonEmptyIterator> NonEmptyIterator for StepBy<I>

Source§

impl<I: NonEmptyIterator> NonEmptyIterator for Take<I>

Source§

impl<I: NonEmptyIterator, F: FnMut(&I::Item)> NonEmptyIterator for Inspect<I, F>

Source§

impl<I: NonEmptyIterator, J: Iterator<Item = I::Item>> NonEmptyIterator for Chain<I, J>

Source§

impl<I: NonEmptyIterator, J: IntoNonEmptyIterator, F: FnMut(I::Item) -> J> NonEmptyIterator for FlatMap<I, J, F>

Source§

impl<I: NonEmptyIterator, J: NonEmptyIterator> NonEmptyIterator for Zip<I, J>

Source§

impl<T> NonEmptyIterator for Once<T>

Source§

impl<T, F: FnMut() -> T> NonEmptyIterator for RepeatWith<F>

Source§

impl<T, F: FnOnce() -> T> NonEmptyIterator for OnceWith<F>

Source§

impl<T, S: FnMut(&T) -> Option<T>> NonEmptyIterator for Successors<T, S>

Source§

impl<T: Clone> NonEmptyIterator for Repeat<T>

Source§

impl<T: Clone> NonEmptyIterator for RepeatN<T>

Source§

impl<U, I: NonEmptyIterator, F: FnMut(I::Item) -> U> NonEmptyIterator for Map<I, F>