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§
Sourcefn consume(self) -> (Self::Item, Self::IntoIter)
fn consume(self) -> (Self::Item, Self::IntoIter)
Consumes the non-empty iterator, returning the next item along with the possibly empty iterator.
Sourcefn zip<I: IntoNonEmptyIterator>(
self,
other: I,
) -> Zip<Self, I::IntoNonEmptyIter>
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.
§Difference from Iterator
Note that the argument is required to be IntoNonEmptyIterator.
§Non-empty
The returned iterator is guaranteed to be non-empty.
Sourcefn none<P: FnMut(Self::Item) -> bool>(self, predicate: P) -> bool
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.
Sourcefn unzip<T, U, C: Default + Extend<T>, D: Default + Extend<U>>(self) -> (C, D)where
Self: NonEmptyIterator<Item = (T, U)>,
fn unzip<T, U, C: Default + Extend<T>, D: Default + Extend<U>>(self) -> (C, D)where
Self: NonEmptyIterator<Item = (T, U)>,
Sourcefn collect<C: FromIterator<Self::Item>>(self) -> C
fn collect<C: FromIterator<Self::Item>>(self) -> C
Equivalent to collect on Iterator.
See also collect_non_empty.
Sourcefn collect_non_empty<C: FromNonEmptyIterator<Self::Item>>(self) -> C
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.
Sourcefn flat_map<J: IntoNonEmptyIterator, F: FnMut(Self::Item) -> J>(
self,
function: F,
) -> FlatMap<Self, J, F>
fn flat_map<J: IntoNonEmptyIterator, F: FnMut(Self::Item) -> J>( self, function: F, ) -> FlatMap<Self, J, F>
Sourcefn flatten(self) -> Flatten<Self>where
Self::Item: IntoNonEmptyIterator,
fn flatten(self) -> Flatten<Self>where
Self::Item: IntoNonEmptyIterator,
Sourcefn filter_map<T, F: FnMut(Self::Item) -> Option<T>>(
self,
function: F,
) -> FilterMap<Self::IntoIter, F>
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.
Sourcefn max_by_key<K: Ord, F: FnMut(&Self::Item) -> K>(
self,
function: F,
) -> Self::Item
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.
Sourcefn min_by_key<K: Ord, F: FnMut(&Self::Item) -> K>(
self,
function: F,
) -> Self::Item
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.
Sourcefn skip_while<P: FnMut(&Self::Item) -> bool>(
self,
predicate: P,
) -> SkipWhile<Self::IntoIter, P>
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.
Sourcefn take_while<P: FnMut(&Self::Item) -> bool>(
self,
predicate: P,
) -> TakeWhile<Self::IntoIter, P>
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.
Sourcefn map_while<T, P: FnMut(Self::Item) -> Option<T>>(
self,
predicate: P,
) -> MapWhile<Self::IntoIter, P>
fn map_while<T, P: FnMut(Self::Item) -> Option<T>>( self, predicate: P, ) -> MapWhile<Self::IntoIter, P>
Sourcefn scan<S, T, F: FnMut(&mut S, Self::Item) -> Option<T>>(
self,
initial: S,
function: F,
) -> Scan<Self::IntoIter, S, F>
fn scan<S, T, F: FnMut(&mut S, Self::Item) -> Option<T>>( self, initial: S, function: F, ) -> Scan<Self::IntoIter, S, F>
Sourcefn partition<C: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool>(
self,
function: F,
) -> (C, C)
fn partition<C: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool>( self, function: F, ) -> (C, C)
Sourcefn cmp<I: IntoIterator<Item = Self::Item>>(self, other: I) -> Ordering
fn cmp<I: IntoIterator<Item = Self::Item>>(self, other: I) -> Ordering
Sourcefn partial_cmp<I: IntoIterator>(self, other: I) -> Option<Ordering>
fn partial_cmp<I: IntoIterator>(self, other: I) -> Option<Ordering>
Equivalent to partial_cmp on Iterator.
Sourcefn eq<I: IntoIterator>(self, other: I) -> bool
fn eq<I: IntoIterator>(self, other: I) -> bool
Sourcefn ne<I: IntoIterator>(self, other: I) -> bool
fn ne<I: IntoIterator>(self, other: I) -> bool
Sourcefn lt<I: IntoIterator>(self, other: I) -> bool
fn lt<I: IntoIterator>(self, other: I) -> bool
Sourcefn le<I: IntoIterator>(self, other: I) -> bool
fn le<I: IntoIterator>(self, other: I) -> bool
Sourcefn gt<I: IntoIterator>(self, other: I) -> bool
fn gt<I: IntoIterator>(self, other: I) -> bool
Sourcefn ge<I: IntoIterator>(self, other: I) -> bool
fn ge<I: IntoIterator>(self, other: I) -> bool
Sourcefn is_sorted_by<F: FnMut(&Self::Item, &Self::Item) -> bool>(
self,
function: F,
) -> bool
fn is_sorted_by<F: FnMut(&Self::Item, &Self::Item) -> bool>( self, function: F, ) -> bool
Equivalent to is_sorted_by on Iterator.
Sourcefn is_sorted_by_key<K: PartialOrd, F: FnMut(Self::Item) -> K>(
self,
function: F,
) -> bool
fn is_sorted_by_key<K: PartialOrd, F: FnMut(Self::Item) -> K>( self, function: F, ) -> bool
Equivalent to is_sorted_by_key on Iterator.
Sourcefn collect_into<C: Extend<Self::Item>>(self, collection: &mut C) -> &mut C
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.
Sourcefn rev(self) -> Rev<Self>where
Self::IntoIter: DoubleEndedIterator,
fn rev(self) -> Rev<Self>where
Self::IntoIter: DoubleEndedIterator,
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.