Trait otter::prelude::otter_base::crates::itertools::__std_iter::IntoIterator
1.0.0 · source · [−]pub trait IntoIterator {
type Item;
type IntoIter: Iterator
where
<Self::IntoIter as Iterator>::Item == Self::Item;
fn into_iter(self) -> Self::IntoIter;
}
Expand description
Conversion into an Iterator
.
By implementing IntoIterator
for a type, you define how it will be
converted to an iterator. This is common for types which describe a
collection of some kind.
One benefit of implementing IntoIterator
is that your type will work
with Rust’s for
loop syntax.
See also: FromIterator
.
Examples
Basic usage:
let v = [1, 2, 3];
let mut iter = v.into_iter();
assert_eq!(Some(1), iter.next());
assert_eq!(Some(2), iter.next());
assert_eq!(Some(3), iter.next());
assert_eq!(None, iter.next());
Implementing IntoIterator
for your type:
// A sample collection, that's just a wrapper over Vec<T>
#[derive(Debug)]
struct MyCollection(Vec<i32>);
// Let's give it some methods so we can create one and add things
// to it.
impl MyCollection {
fn new() -> MyCollection {
MyCollection(Vec::new())
}
fn add(&mut self, elem: i32) {
self.0.push(elem);
}
}
// and we'll implement IntoIterator
impl IntoIterator for MyCollection {
type Item = i32;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
// Now we can make a new collection...
let mut c = MyCollection::new();
// ... add some stuff to it ...
c.add(0);
c.add(1);
c.add(2);
// ... and then turn it into an Iterator:
for (i, n) in c.into_iter().enumerate() {
assert_eq!(i as i32, n);
}
It is common to use IntoIterator
as a trait bound. This allows
the input collection type to change, so long as it is still an
iterator. Additional bounds can be specified by restricting on
Item
:
fn collect_as_strings<T>(collection: T) -> Vec<String>
where
T: IntoIterator,
T::Item: std::fmt::Debug,
{
collection
.into_iter()
.map(|item| format!("{item:?}"))
.collect()
}
Required Associated Types
Required Methods
Creates an iterator from a value.
See the module-level documentation for more.
Examples
Basic usage:
let v = [1, 2, 3];
let mut iter = v.into_iter();
assert_eq!(Some(1), iter.next());
assert_eq!(Some(2), iter.next());
assert_eq!(Some(3), iter.next());
assert_eq!(None, iter.next());
Implementors
sourceimpl IntoIterator for otter::prelude::rand::seq::index::IndexVec
impl IntoIterator for otter::prelude::rand::seq::index::IndexVec
type Item = usize
type IntoIter = IndexVecIntoIter
impl IntoIterator for Dir
impl IntoIterator for Dir
sourceimpl IntoIterator for otter::prelude::toml::value::Map<String, Value>
impl IntoIterator for otter::prelude::toml::value::Map<String, Value>
sourceimpl IntoIterator for otter::prelude::otter_base::crates::serde_json::Map<String, Value>
impl IntoIterator for otter::prelude::otter_base::crates::serde_json::Map<String, Value>
sourceimpl IntoIterator for regex::re_set::bytes::SetMatches
impl IntoIterator for regex::re_set::bytes::SetMatches
type IntoIter = SetMatchesIntoIter
type Item = usize
sourceimpl IntoIterator for regex::re_set::unicode::SetMatches
impl IntoIterator for regex::re_set::unicode::SetMatches
type IntoIter = SetMatchesIntoIter
type Item = usize
impl IntoIterator for CharRange
impl IntoIterator for CharRange
impl IntoIterator for WalkDir
impl IntoIterator for WalkDir
impl<'a> IntoIterator for &'a Interfaces
impl<'a> IntoIterator for &'a Interfaces
type IntoIter = InterfacesIter<'a>
type Item = &'a Interface
impl<'a> IntoIterator for &'a SigSet
impl<'a> IntoIterator for &'a SigSet
type Item = Signal
type IntoIter = SigSetIter<'a>
sourceimpl<'a> IntoIterator for &'a otter::prelude::toml::value::Map<String, Value>
impl<'a> IntoIterator for &'a otter::prelude::toml::value::Map<String, Value>
1.10.0 · sourceimpl<'a> IntoIterator for &'a UnixListener
impl<'a> IntoIterator for &'a UnixListener
sourceimpl<'a> IntoIterator for &'a otter::prelude::otter_base::crates::serde_json::Map<String, Value>
impl<'a> IntoIterator for &'a otter::prelude::otter_base::crates::serde_json::Map<String, Value>
sourceimpl<'a> IntoIterator for &'a regex::re_set::bytes::SetMatches
impl<'a> IntoIterator for &'a regex::re_set::bytes::SetMatches
type IntoIter = SetMatchesIter<'a>
type Item = usize
sourceimpl<'a> IntoIterator for &'a regex::re_set::unicode::SetMatches
impl<'a> IntoIterator for &'a regex::re_set::unicode::SetMatches
type IntoIter = SetMatchesIter<'a>
type Item = usize
impl<'a> IntoIterator for &'a Events
impl<'a> IntoIterator for &'a Events
impl<'a> IntoIterator for &'a Utf8Sequence
impl<'a> IntoIterator for &'a Utf8Sequence
sourceimpl<'a> IntoIterator for &'a mut otter::prelude::toml::value::Map<String, Value>
impl<'a> IntoIterator for &'a mut otter::prelude::toml::value::Map<String, Value>
sourceimpl<'a> IntoIterator for &'a mut otter::prelude::otter_base::crates::serde_json::Map<String, Value>
impl<'a> IntoIterator for &'a mut otter::prelude::otter_base::crates::serde_json::Map<String, Value>
impl<'a, A> IntoIterator for &'a ArrayVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a ArrayVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a SmallVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a SmallVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a TinyVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a TinyVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a mut ArrayVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a mut ArrayVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a mut SmallVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a mut SmallVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a mut TinyVec<A> where
A: Array,
impl<'a, A> IntoIterator for &'a mut TinyVec<A> where
A: Array,
sourceimpl<'a, I> IntoIterator for &'a IntoChunks<I> where
I: Iterator,
<I as Iterator>::Item: 'a,
impl<'a, I> IntoIterator for &'a IntoChunks<I> where
I: Iterator,
<I as Iterator>::Item: 'a,
sourceimpl<'a, I> IntoIterator for &'a RcIter<I> where
I: Iterator,
impl<'a, I> IntoIterator for &'a RcIter<I> where
I: Iterator,
Return an iterator from &RcIter<I>
(by simply cloning it).
sourceimpl<'a, I, T> IntoIterator for &'a IndexSlice<I, [T]> where
I: Idx,
impl<'a, I, T> IntoIterator for &'a IndexSlice<I, [T]> where
I: Idx,
sourceimpl<'a, I, T> IntoIterator for &'a otter::imports::IndexVec<I, T> where
I: Idx,
impl<'a, I, T> IntoIterator for &'a otter::imports::IndexVec<I, T> where
I: Idx,
sourceimpl<'a, I, T> IntoIterator for &'a mut IndexSlice<I, [T]> where
I: Idx,
impl<'a, I, T> IntoIterator for &'a mut IndexSlice<I, [T]> where
I: Idx,
sourceimpl<'a, I, T> IntoIterator for &'a mut otter::imports::IndexVec<I, T> where
I: Idx,
impl<'a, I, T> IntoIterator for &'a mut otter::imports::IndexVec<I, T> where
I: Idx,
sourceimpl<'a, K, I, F> IntoIterator for &'a GroupBy<K, I, F> where
I: Iterator,
F: for<'_> FnMut(&<I as Iterator>::Item) -> K,
K: PartialEq<K>,
<I as Iterator>::Item: 'a,
impl<'a, K, I, F> IntoIterator for &'a GroupBy<K, I, F> where
I: Iterator,
F: for<'_> FnMut(&<I as Iterator>::Item) -> K,
K: PartialEq<K>,
<I as Iterator>::Item: 'a,
sourceimpl<'a, K, V> IntoIterator for &'a EnumMap<K, V> where
K: EnumArray<V>,
impl<'a, K, V> IntoIterator for &'a EnumMap<K, V> where
K: EnumArray<V>,
sourceimpl<'a, K, V> IntoIterator for &'a HopSlotMap<K, V> where
K: Key,
impl<'a, K, V> IntoIterator for &'a HopSlotMap<K, V> where
K: Key,
sourceimpl<'a, K, V> IntoIterator for &'a SecondaryMap<K, V> where
K: Key,
impl<'a, K, V> IntoIterator for &'a SecondaryMap<K, V> where
K: Key,
sourceimpl<'a, K, V> IntoIterator for &'a SlotMap<K, V> where
K: Key,
impl<'a, K, V> IntoIterator for &'a SlotMap<K, V> where
K: Key,
sourceimpl<'a, K, V> IntoIterator for &'a DenseSlotMap<K, V> where
K: 'a + Key,
impl<'a, K, V> IntoIterator for &'a DenseSlotMap<K, V> where
K: 'a + Key,
sourceimpl<'a, K, V> IntoIterator for &'a phf::map::Map<K, V>
impl<'a, K, V> IntoIterator for &'a phf::map::Map<K, V>
sourceimpl<'a, K, V> IntoIterator for &'a OrderedMap<K, V>
impl<'a, K, V> IntoIterator for &'a OrderedMap<K, V>
sourceimpl<'a, K, V> IntoIterator for &'a mut EnumMap<K, V> where
K: EnumArray<V>,
impl<'a, K, V> IntoIterator for &'a mut EnumMap<K, V> where
K: EnumArray<V>,
sourceimpl<'a, K, V> IntoIterator for &'a mut HopSlotMap<K, V> where
K: Key,
impl<'a, K, V> IntoIterator for &'a mut HopSlotMap<K, V> where
K: Key,
sourceimpl<'a, K, V> IntoIterator for &'a mut SecondaryMap<K, V> where
K: Key,
impl<'a, K, V> IntoIterator for &'a mut SecondaryMap<K, V> where
K: Key,
sourceimpl<'a, K, V> IntoIterator for &'a mut SlotMap<K, V> where
K: Key,
impl<'a, K, V> IntoIterator for &'a mut SlotMap<K, V> where
K: Key,
sourceimpl<'a, K, V> IntoIterator for &'a mut DenseSlotMap<K, V> where
K: 'a + Key,
impl<'a, K, V> IntoIterator for &'a mut DenseSlotMap<K, V> where
K: 'a + Key,
sourceimpl<'a, K, V, A> IntoIterator for &'a BTreeMap<K, V, A> where
A: Allocator + Clone,
impl<'a, K, V, A> IntoIterator for &'a BTreeMap<K, V, A> where
A: Allocator + Clone,
sourceimpl<'a, K, V, A> IntoIterator for &'a mut BTreeMap<K, V, A> where
A: Allocator + Clone,
impl<'a, K, V, A> IntoIterator for &'a mut BTreeMap<K, V, A> where
A: Allocator + Clone,
sourceimpl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S>
sourceimpl<'a, K, V, S> IntoIterator for &'a SparseSecondaryMap<K, V, S> where
K: Key,
S: BuildHasher,
impl<'a, K, V, S> IntoIterator for &'a SparseSecondaryMap<K, V, S> where
K: Key,
S: BuildHasher,
sourceimpl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S>
sourceimpl<'a, K, V, S> IntoIterator for &'a mut SparseSecondaryMap<K, V, S> where
K: Key,
S: BuildHasher,
impl<'a, K, V, S> IntoIterator for &'a mut SparseSecondaryMap<K, V, S> where
K: Key,
S: BuildHasher,
1.4.0 · sourceimpl<'a, T> IntoIterator for &'a Option<T>
impl<'a, T> IntoIterator for &'a Option<T>
sourceimpl<'a, T> IntoIterator for &'a BinaryHeap<T>
impl<'a, T> IntoIterator for &'a BinaryHeap<T>
sourceimpl<'a, T> IntoIterator for &'a LinkedList<T>
impl<'a, T> IntoIterator for &'a LinkedList<T>
sourceimpl<'a, T> IntoIterator for &'a OrderedSet<T>
impl<'a, T> IntoIterator for &'a OrderedSet<T>
impl<'a, T> IntoIterator for &'a Slab<T>
impl<'a, T> IntoIterator for &'a Slab<T>
impl<'a, T> IntoIterator for &'a ThreadLocal<T> where
T: Send + Sync,
impl<'a, T> IntoIterator for &'a ThreadLocal<T> where
T: Send + Sync,
1.4.0 · sourceimpl<'a, T> IntoIterator for &'a mut Option<T>
impl<'a, T> IntoIterator for &'a mut Option<T>
sourceimpl<'a, T> IntoIterator for &'a mut LinkedList<T>
impl<'a, T> IntoIterator for &'a mut LinkedList<T>
impl<'a, T> IntoIterator for &'a mut CachedThreadLocal<T> where
T: 'a + Send,
impl<'a, T> IntoIterator for &'a mut CachedThreadLocal<T> where
T: 'a + Send,
impl<'a, T> IntoIterator for &'a mut Slab<T>
impl<'a, T> IntoIterator for &'a mut Slab<T>
impl<'a, T> IntoIterator for &'a mut ThreadLocal<T> where
T: Send,
impl<'a, T> IntoIterator for &'a mut ThreadLocal<T> where
T: Send,
sourceimpl<'a, T, A> IntoIterator for &'a BTreeSet<T, A> where
A: Allocator + Clone,
impl<'a, T, A> IntoIterator for &'a BTreeSet<T, A> where
A: Allocator + Clone,
sourceimpl<'a, T, A> IntoIterator for &'a VecDeque<T, A> where
A: Allocator,
impl<'a, T, A> IntoIterator for &'a VecDeque<T, A> where
A: Allocator,
sourceimpl<'a, T, A> IntoIterator for &'a Vec<T, A> where
A: Allocator,
impl<'a, T, A> IntoIterator for &'a Vec<T, A> where
A: Allocator,
sourceimpl<'a, T, A> IntoIterator for &'a mut VecDeque<T, A> where
A: Allocator,
impl<'a, T, A> IntoIterator for &'a mut VecDeque<T, A> where
A: Allocator,
sourceimpl<'a, T, A> IntoIterator for &'a mut Vec<T, A> where
A: Allocator,
impl<'a, T, A> IntoIterator for &'a mut Vec<T, A> where
A: Allocator,
1.4.0 · sourceimpl<'a, T, E> IntoIterator for &'a Result<T, E>
impl<'a, T, E> IntoIterator for &'a Result<T, E>
1.4.0 · sourceimpl<'a, T, E> IntoIterator for &'a mut Result<T, E>
impl<'a, T, E> IntoIterator for &'a mut Result<T, E>
impl<'a, T, N> IntoIterator for &'a GenericArray<T, N> where
T: 'a,
N: ArrayLength<T>,
impl<'a, T, N> IntoIterator for &'a GenericArray<T, N> where
T: 'a,
N: ArrayLength<T>,
impl<'a, T, N> IntoIterator for &'a mut GenericArray<T, N> where
T: 'a,
N: ArrayLength<T>,
impl<'a, T, N> IntoIterator for &'a mut GenericArray<T, N> where
T: 'a,
N: ArrayLength<T>,
sourceimpl<'a, T, const CAP: usize> IntoIterator for &'a otter::prelude::otter_base::prelude::ArrayVec<T, CAP> where
T: 'a,
impl<'a, T, const CAP: usize> IntoIterator for &'a otter::prelude::otter_base::prelude::ArrayVec<T, CAP> where
T: 'a,
Iterate the ArrayVec
with references to each element.
use arrayvec::ArrayVec;
let array = ArrayVec::from([1, 2, 3]);
for elt in &array {
// ...
}
sourceimpl<'a, T, const CAP: usize> IntoIterator for &'a mut otter::prelude::otter_base::prelude::ArrayVec<T, CAP> where
T: 'a,
impl<'a, T, const CAP: usize> IntoIterator for &'a mut otter::prelude::otter_base::prelude::ArrayVec<T, CAP> where
T: 'a,
Iterate the ArrayVec
with mutable references to each element.
use arrayvec::ArrayVec;
let mut array = ArrayVec::from([1, 2, 3]);
for elt in &mut array {
// ...
}
sourceimpl<'a, T, const N: usize> IntoIterator for &'a [T; N]
impl<'a, T, const N: usize> IntoIterator for &'a [T; N]
sourceimpl<'a, T, const N: usize> IntoIterator for &'a mut [T; N]
impl<'a, T, const N: usize> IntoIterator for &'a mut [T; N]
impl<'entries, EntryData> IntoIterator for &'entries VecList<EntryData>
impl<'entries, EntryData> IntoIterator for &'entries VecList<EntryData>
impl<'entries, EntryData> IntoIterator for &'entries mut VecList<EntryData>
impl<'entries, EntryData> IntoIterator for &'entries mut VecList<EntryData>
type IntoIter = IterMut<'entries, EntryData>
type Item = &'entries mut EntryData
sourceimpl<'p> IntoIterator for &'p mut GPieces
impl<'p> IntoIterator for &'p mut GPieces
impl<'s, T> IntoIterator for SliceVec<'s, T>
impl<'s, T> IntoIterator for SliceVec<'s, T>
sourceimpl<'v, T, I> IntoIterator for &'v Deque<T, I> where
I: Offset,
impl<'v, T, I> IntoIterator for &'v Deque<T, I> where
I: Offset,
sourceimpl<'z> IntoIterator for &'z IndexedZip
impl<'z> IntoIterator for &'z IndexedZip
impl<A> IntoIterator for ArrayVec<A> where
A: Array,
impl<A> IntoIterator for ArrayVec<A> where
A: Array,
impl<A> IntoIterator for SmallVec<A> where
A: Array,
impl<A> IntoIterator for SmallVec<A> where
A: Array,
impl<A> IntoIterator for TinyVec<A> where
A: Array,
impl<A> IntoIterator for TinyVec<A> where
A: Array,
impl<EntryData> IntoIterator for VecList<EntryData>
impl<EntryData> IntoIterator for VecList<EntryData>
const: unstable · sourceimpl<I> IntoIterator for I where
I: Iterator,
impl<I> IntoIterator for I where
I: Iterator,
sourceimpl<I, A> IntoIterator for Box<IndexSlice<I, [A]>, Global> where
I: Idx,
impl<I, A> IntoIterator for Box<IndexSlice<I, [A]>, Global> where
I: Idx,
sourceimpl<I, T> IntoIterator for otter::imports::IndexVec<I, T> where
I: Idx,
impl<I, T> IntoIterator for otter::imports::IndexVec<I, T> where
I: Idx,
sourceimpl<K, V> IntoIterator for EnumMap<K, V> where
K: EnumArray<V>,
impl<K, V> IntoIterator for EnumMap<K, V> where
K: EnumArray<V>,
sourceimpl<K, V> IntoIterator for HopSlotMap<K, V> where
K: Key,
impl<K, V> IntoIterator for HopSlotMap<K, V> where
K: Key,
sourceimpl<K, V> IntoIterator for SecondaryMap<K, V> where
K: Key,
impl<K, V> IntoIterator for SecondaryMap<K, V> where
K: Key,
sourceimpl<K, V> IntoIterator for SlotMap<K, V> where
K: Key,
impl<K, V> IntoIterator for SlotMap<K, V> where
K: Key,
sourceimpl<K, V> IntoIterator for DenseSlotMap<K, V> where
K: Key,
impl<K, V> IntoIterator for DenseSlotMap<K, V> where
K: Key,
sourceimpl<K, V, A> IntoIterator for BTreeMap<K, V, A> where
A: Allocator + Clone,
impl<K, V, A> IntoIterator for BTreeMap<K, V, A> where
A: Allocator + Clone,
sourceimpl<K, V, S> IntoIterator for HashMap<K, V, S>
impl<K, V, S> IntoIterator for HashMap<K, V, S>
sourceimpl<K, V, S> IntoIterator for SparseSecondaryMap<K, V, S> where
K: Key,
S: BuildHasher,
impl<K, V, S> IntoIterator for SparseSecondaryMap<K, V, S> where
K: Key,
S: BuildHasher,
sourceimpl<T> IntoIterator for iter<T> where
T: Collect,
impl<T> IntoIterator for iter<T> where
T: Collect,
sourceimpl<T> IntoIterator for BinaryHeap<T>
impl<T> IntoIterator for BinaryHeap<T>
sourceimpl<T> IntoIterator for LinkedList<T>
impl<T> IntoIterator for LinkedList<T>
impl<T> IntoIterator for CachedThreadLocal<T> where
T: Send,
impl<T> IntoIterator for CachedThreadLocal<T> where
T: Send,
impl<T> IntoIterator for Slab<T>
impl<T> IntoIterator for Slab<T>
impl<T> IntoIterator for ThreadLocal<T> where
T: Send,
impl<T> IntoIterator for ThreadLocal<T> where
T: Send,
sourceimpl<T, A> IntoIterator for BTreeSet<T, A> where
A: Allocator + Clone,
impl<T, A> IntoIterator for BTreeSet<T, A> where
A: Allocator + Clone,
sourceimpl<T, A> IntoIterator for VecDeque<T, A> where
A: Allocator,
impl<T, A> IntoIterator for VecDeque<T, A> where
A: Allocator,
sourceimpl<T, A> IntoIterator for Vec<T, A> where
A: Allocator,
impl<T, A> IntoIterator for Vec<T, A> where
A: Allocator,
impl<T, N> IntoIterator for GenericArray<T, N> where
N: ArrayLength<T>,
impl<T, N> IntoIterator for GenericArray<T, N> where
N: ArrayLength<T>,
type Item = T
type IntoIter = GenericArrayIter<T, N>
sourceimpl<T, const CAP: usize> IntoIterator for otter::prelude::otter_base::prelude::ArrayVec<T, CAP>
impl<T, const CAP: usize> IntoIterator for otter::prelude::otter_base::prelude::ArrayVec<T, CAP>
Iterate the ArrayVec
with each element by value.
The vector is consumed by this operation.
use arrayvec::ArrayVec;
for elt in ArrayVec::from([1, 2, 3]) {
// ...
}