Trait wasmtime_environ::__core::prelude::rust_2021::IntoIterator
1.0.0 · source · [−]pub trait IntoIterator {
type Item;
type IntoIter: Iterator<Item = Self::Item>;
const 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
sourceconst fn into_iter(self) -> Self::IntoIter
const fn into_iter(self) -> Self::IntoIter
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
1.10.0 · sourceimpl<'a> IntoIterator for &'a UnixListener
impl<'a> IntoIterator for &'a UnixListener
sourceimpl<'a> IntoIterator for CodeSectionReader<'a>
impl<'a> IntoIterator for CodeSectionReader<'a>
type Item = Result<FunctionBody<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<CodeSectionReader<'a>>
sourceimpl<'a> IntoIterator for ComponentAliasSectionReader<'a>
impl<'a> IntoIterator for ComponentAliasSectionReader<'a>
type Item = Result<ComponentAlias<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentAliasSectionReader<'a>>
sourceimpl<'a> IntoIterator for ComponentCanonicalSectionReader<'a>
impl<'a> IntoIterator for ComponentCanonicalSectionReader<'a>
sourceimpl<'a> IntoIterator for ComponentExportSectionReader<'a>
impl<'a> IntoIterator for ComponentExportSectionReader<'a>
type Item = Result<ComponentExport<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentExportSectionReader<'a>>
sourceimpl<'a> IntoIterator for ComponentImportSectionReader<'a>
impl<'a> IntoIterator for ComponentImportSectionReader<'a>
type Item = Result<ComponentImport<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentImportSectionReader<'a>>
sourceimpl<'a> IntoIterator for ComponentInstanceSectionReader<'a>
impl<'a> IntoIterator for ComponentInstanceSectionReader<'a>
type Item = Result<ComponentInstance<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentInstanceSectionReader<'a>>
sourceimpl<'a> IntoIterator for ComponentTypeSectionReader<'a>
impl<'a> IntoIterator for ComponentTypeSectionReader<'a>
type Item = Result<ComponentType<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentTypeSectionReader<'a>>
sourceimpl<'a> IntoIterator for CoreTypeSectionReader<'a>
impl<'a> IntoIterator for CoreTypeSectionReader<'a>
type Item = Result<CoreType<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<CoreTypeSectionReader<'a>>
sourceimpl<'a> IntoIterator for DataSectionReader<'a>
impl<'a> IntoIterator for DataSectionReader<'a>
type Item = Result<Data<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<DataSectionReader<'a>>
sourceimpl<'a> IntoIterator for ElementItemsReader<'a>
impl<'a> IntoIterator for ElementItemsReader<'a>
type Item = Result<ElementItem<'a>, BinaryReaderError>
type IntoIter = ElementItemsIterator<'a>
sourceimpl<'a> IntoIterator for ElementSectionReader<'a>
impl<'a> IntoIterator for ElementSectionReader<'a>
type Item = Result<Element<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ElementSectionReader<'a>>
sourceimpl<'a> IntoIterator for ExportSectionReader<'a>
impl<'a> IntoIterator for ExportSectionReader<'a>
type Item = Result<Export<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ExportSectionReader<'a>>
sourceimpl<'a> IntoIterator for FunctionSectionReader<'a>
impl<'a> IntoIterator for FunctionSectionReader<'a>
type Item = Result<u32, BinaryReaderError>
type IntoIter = SectionIteratorLimited<FunctionSectionReader<'a>>
sourceimpl<'a> IntoIterator for GlobalSectionReader<'a>
impl<'a> IntoIterator for GlobalSectionReader<'a>
type Item = Result<Global<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<GlobalSectionReader<'a>>
sourceimpl<'a> IntoIterator for ImportSectionReader<'a>
impl<'a> IntoIterator for ImportSectionReader<'a>
type Item = Result<Import<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ImportSectionReader<'a>>
sourceimpl<'a> IntoIterator for InstanceSectionReader<'a>
impl<'a> IntoIterator for InstanceSectionReader<'a>
type Item = Result<Instance<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<InstanceSectionReader<'a>>
sourceimpl<'a> IntoIterator for LinkingSectionReader<'a>
impl<'a> IntoIterator for LinkingSectionReader<'a>
type Item = Result<LinkingType, BinaryReaderError>
type IntoIter = SectionIteratorLimited<LinkingSectionReader<'a>>
sourceimpl<'a> IntoIterator for LocalsReader<'a>
impl<'a> IntoIterator for LocalsReader<'a>
type Item = Result<(u32, ValType), BinaryReaderError>
type IntoIter = LocalsIterator<'a>
sourceimpl<'a> IntoIterator for MemorySectionReader<'a>
impl<'a> IntoIterator for MemorySectionReader<'a>
type Item = Result<MemoryType, BinaryReaderError>
type IntoIter = SectionIteratorLimited<MemorySectionReader<'a>>
sourceimpl<'a> IntoIterator for NameSectionReader<'a>
impl<'a> IntoIterator for NameSectionReader<'a>
type Item = Result<Name<'a>, BinaryReaderError>
type IntoIter = SectionIterator<NameSectionReader<'a>>
sourceimpl<'a> IntoIterator for OperatorsReader<'a>
impl<'a> IntoIterator for OperatorsReader<'a>
type Item = Result<Operator<'a>, BinaryReaderError>
type IntoIter = OperatorsIterator<'a>
sourceimpl<'a> IntoIterator for ProducersFieldValuesReader<'a>
impl<'a> IntoIterator for ProducersFieldValuesReader<'a>
type Item = Result<ProducersFieldValue<'a>, BinaryReaderError>
type IntoIter = ProducersFieldValuesIterator<'a>
sourceimpl<'a> IntoIterator for ProducersSectionReader<'a>
impl<'a> IntoIterator for ProducersSectionReader<'a>
type Item = Result<ProducersField<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ProducersSectionReader<'a>>
sourceimpl<'a> IntoIterator for RelocSectionReader<'a>
impl<'a> IntoIterator for RelocSectionReader<'a>
type Item = Result<Reloc, BinaryReaderError>
type IntoIter = SectionIteratorLimited<RelocSectionReader<'a>>
sourceimpl<'a> IntoIterator for TableSectionReader<'a>
impl<'a> IntoIterator for TableSectionReader<'a>
type Item = Result<TableType, BinaryReaderError>
type IntoIter = SectionIteratorLimited<TableSectionReader<'a>>
sourceimpl<'a> IntoIterator for TagSectionReader<'a>
impl<'a> IntoIterator for TagSectionReader<'a>
type Item = Result<TagType, BinaryReaderError>
type IntoIter = SectionIteratorLimited<TagSectionReader<'a>>
sourceimpl<'a> IntoIterator for TypeSectionReader<'a>
impl<'a> IntoIterator for TypeSectionReader<'a>
type Item = Result<Type, BinaryReaderError>
type IntoIter = SectionIteratorLimited<TypeSectionReader<'a>>
sourceimpl<'a, K, V> IntoIterator for &'a BoxedSlice<K, V>where
K: EntityRef,
impl<'a, K, V> IntoIterator for &'a BoxedSlice<K, V>where
K: EntityRef,
sourceimpl<'a, K, V> IntoIterator for &'a PrimaryMap<K, V>where
K: EntityRef,
impl<'a, K, V> IntoIterator for &'a PrimaryMap<K, V>where
K: EntityRef,
sourceimpl<'a, K, V> IntoIterator for &'a SparseMap<K, V>where
K: EntityRef,
V: SparseMapValue<K>,
impl<'a, K, V> IntoIterator for &'a SparseMap<K, V>where
K: EntityRef,
V: SparseMapValue<K>,
Iterating over the elements of a set.