Trait scrypto_test::prelude::rust::iter::IntoIterator
1.0.0 · source · pub trait IntoIterator {
type Item;
type IntoIter: Iterator<Item = Self::Item>;
// Required method
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§
1.0.0 · sourcefn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value.
See the module-level documentation for more.
§Examples
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.29.0 · source§impl IntoIterator for proc_macro::TokenStream
impl IntoIterator for proc_macro::TokenStream
source§impl IntoIterator for proc_macro2::TokenStream
impl IntoIterator for proc_macro2::TokenStream
source§impl IntoIterator for regex::regexset::bytes::SetMatches
impl IntoIterator for regex::regexset::bytes::SetMatches
source§impl IntoIterator for regex::regexset::string::SetMatches
impl IntoIterator for regex::regexset::string::SetMatches
source§impl IntoIterator for CreateFlags
impl IntoIterator for CreateFlags
type Item = CreateFlags
type IntoIter = Iter<CreateFlags>
source§impl IntoIterator for WatchFlags
impl IntoIterator for WatchFlags
type Item = WatchFlags
type IntoIter = Iter<WatchFlags>
source§impl IntoIterator for FallocateFlags
impl IntoIterator for FallocateFlags
type Item = FallocateFlags
type IntoIter = Iter<FallocateFlags>
source§impl IntoIterator for MemfdFlags
impl IntoIterator for MemfdFlags
type Item = MemfdFlags
type IntoIter = Iter<MemfdFlags>
source§impl IntoIterator for RenameFlags
impl IntoIterator for RenameFlags
type Item = RenameFlags
type IntoIter = Iter<RenameFlags>
source§impl IntoIterator for ResolveFlags
impl IntoIterator for ResolveFlags
type Item = ResolveFlags
type IntoIter = Iter<ResolveFlags>
source§impl IntoIterator for StatVfsMountFlags
impl IntoIterator for StatVfsMountFlags
type Item = StatVfsMountFlags
type IntoIter = Iter<StatVfsMountFlags>
source§impl IntoIterator for StatxFlags
impl IntoIterator for StatxFlags
type Item = StatxFlags
type IntoIter = Iter<StatxFlags>
source§impl IntoIterator for ReadWriteFlags
impl IntoIterator for ReadWriteFlags
type Item = ReadWriteFlags
type IntoIter = Iter<ReadWriteFlags>
source§impl IntoIterator for MountFlags
impl IntoIterator for MountFlags
type Item = MountFlags
type IntoIter = Iter<MountFlags>
source§impl IntoIterator for MountPropagationFlags
impl IntoIterator for MountPropagationFlags
type Item = MountPropagationFlags
type IntoIter = Iter<MountPropagationFlags>
source§impl IntoIterator for UnmountFlags
impl IntoIterator for UnmountFlags
type Item = UnmountFlags
type IntoIter = Iter<UnmountFlags>
source§impl IntoIterator for XattrFlags
impl IntoIterator for XattrFlags
type Item = XattrFlags
type IntoIter = Iter<XattrFlags>
source§impl IntoIterator for SerializedSignature
impl IntoIterator for SerializedSignature
source§impl IntoIterator for Array
impl IntoIterator for Array
source§impl IntoIterator for ArrayOfTables
impl IntoIterator for ArrayOfTables
source§impl IntoIterator for InlineTable
impl IntoIterator for InlineTable
type Item = (InternalString, Value)
type IntoIter = Box<dyn Iterator<Item = (InternalString, Value)>>
source§impl IntoIterator for Table
impl IntoIterator for Table
type Item = (InternalString, Item)
type IntoIter = Box<dyn Iterator<Item = (InternalString, Item)>>
source§impl<'a> IntoIterator for &'a Utf8Sequence
impl<'a> IntoIterator for &'a Utf8Sequence
1.10.0 · source§impl<'a> IntoIterator for &'a UnixListener
impl<'a> IntoIterator for &'a UnixListener
source§impl<'a> IntoIterator for &'a regex::regexset::bytes::SetMatches
impl<'a> IntoIterator for &'a regex::regexset::bytes::SetMatches
source§impl<'a> IntoIterator for &'a regex::regexset::string::SetMatches
impl<'a> IntoIterator for &'a regex::regexset::string::SetMatches
source§impl<'a> IntoIterator for &'a SerializedSignature
impl<'a> IntoIterator for &'a SerializedSignature
source§impl<'a> IntoIterator for &'a mut Fields
impl<'a> IntoIterator for &'a mut Fields
source§impl<'a> IntoIterator for ComponentAliasSectionReader<'a>
impl<'a> IntoIterator for ComponentAliasSectionReader<'a>
type Item = Result<ComponentAlias<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentAliasSectionReader<'a>>
source§impl<'a> IntoIterator for ComponentCanonicalSectionReader<'a>
impl<'a> IntoIterator for ComponentCanonicalSectionReader<'a>
source§impl<'a> IntoIterator for ComponentExportSectionReader<'a>
impl<'a> IntoIterator for ComponentExportSectionReader<'a>
type Item = Result<ComponentExport<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentExportSectionReader<'a>>
source§impl<'a> IntoIterator for ComponentImportSectionReader<'a>
impl<'a> IntoIterator for ComponentImportSectionReader<'a>
type Item = Result<ComponentImport<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentImportSectionReader<'a>>
source§impl<'a> IntoIterator for ComponentInstanceSectionReader<'a>
impl<'a> IntoIterator for ComponentInstanceSectionReader<'a>
type Item = Result<ComponentInstance<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentInstanceSectionReader<'a>>
source§impl<'a> IntoIterator for InstanceSectionReader<'a>
impl<'a> IntoIterator for InstanceSectionReader<'a>
type Item = Result<Instance<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<InstanceSectionReader<'a>>
source§impl<'a> IntoIterator for ComponentTypeSectionReader<'a>
impl<'a> IntoIterator for ComponentTypeSectionReader<'a>
type Item = Result<ComponentType<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ComponentTypeSectionReader<'a>>
source§impl<'a> IntoIterator for CoreTypeSectionReader<'a>
impl<'a> IntoIterator for CoreTypeSectionReader<'a>
type Item = Result<CoreType<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<CoreTypeSectionReader<'a>>
source§impl<'a> IntoIterator for CodeSectionReader<'a>
impl<'a> IntoIterator for CodeSectionReader<'a>
type Item = Result<FunctionBody<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<CodeSectionReader<'a>>
source§impl<'a> IntoIterator for wasmparser_nostd::readers::core::code::LocalsReader<'a>
impl<'a> IntoIterator for wasmparser_nostd::readers::core::code::LocalsReader<'a>
type Item = Result<(u32, ValType), BinaryReaderError>
type IntoIter = LocalsIterator<'a>
source§impl<'a> IntoIterator for DataSectionReader<'a>
impl<'a> IntoIterator for DataSectionReader<'a>
type Item = Result<Data<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<DataSectionReader<'a>>
source§impl<'a> IntoIterator for ElementItemsReader<'a>
impl<'a> IntoIterator for ElementItemsReader<'a>
type Item = Result<ElementItem<'a>, BinaryReaderError>
type IntoIter = ElementItemsIterator<'a>
source§impl<'a> IntoIterator for ElementSectionReader<'a>
impl<'a> IntoIterator for ElementSectionReader<'a>
type Item = Result<Element<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ElementSectionReader<'a>>
source§impl<'a> IntoIterator for ExportSectionReader<'a>
impl<'a> IntoIterator for ExportSectionReader<'a>
type Item = Result<Export<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ExportSectionReader<'a>>
source§impl<'a> IntoIterator for FunctionSectionReader<'a>
impl<'a> IntoIterator for FunctionSectionReader<'a>
type Item = Result<u32, BinaryReaderError>
type IntoIter = SectionIteratorLimited<FunctionSectionReader<'a>>
source§impl<'a> IntoIterator for GlobalSectionReader<'a>
impl<'a> IntoIterator for GlobalSectionReader<'a>
type Item = Result<Global<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<GlobalSectionReader<'a>>
source§impl<'a> IntoIterator for ImportSectionReader<'a>
impl<'a> IntoIterator for ImportSectionReader<'a>
type Item = Result<Import<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ImportSectionReader<'a>>
source§impl<'a> IntoIterator for LinkingSectionReader<'a>
impl<'a> IntoIterator for LinkingSectionReader<'a>
type Item = Result<LinkingType, BinaryReaderError>
type IntoIter = SectionIteratorLimited<LinkingSectionReader<'a>>
source§impl<'a> IntoIterator for MemorySectionReader<'a>
impl<'a> IntoIterator for MemorySectionReader<'a>
type Item = Result<MemoryType, BinaryReaderError>
type IntoIter = SectionIteratorLimited<MemorySectionReader<'a>>
source§impl<'a> IntoIterator for NameSectionReader<'a>
impl<'a> IntoIterator for NameSectionReader<'a>
type Item = Result<Name<'a>, BinaryReaderError>
type IntoIter = SectionIterator<NameSectionReader<'a>>
source§impl<'a> IntoIterator for wasmparser_nostd::readers::core::operators::OperatorsReader<'a>
impl<'a> IntoIterator for wasmparser_nostd::readers::core::operators::OperatorsReader<'a>
type Item = Result<Operator<'a>, BinaryReaderError>
type IntoIter = OperatorsIterator<'a>
source§impl<'a> IntoIterator for ProducersFieldValuesReader<'a>
impl<'a> IntoIterator for ProducersFieldValuesReader<'a>
type Item = Result<ProducersFieldValue<'a>, BinaryReaderError>
type IntoIter = ProducersFieldValuesIterator<'a>
source§impl<'a> IntoIterator for ProducersSectionReader<'a>
impl<'a> IntoIterator for ProducersSectionReader<'a>
type Item = Result<ProducersField<'a>, BinaryReaderError>
type IntoIter = SectionIteratorLimited<ProducersSectionReader<'a>>
source§impl<'a> IntoIterator for RelocSectionReader<'a>
impl<'a> IntoIterator for RelocSectionReader<'a>
type Item = Result<Reloc, BinaryReaderError>
type IntoIter = SectionIteratorLimited<RelocSectionReader<'a>>
source§impl<'a> IntoIterator for TableSectionReader<'a>
impl<'a> IntoIterator for TableSectionReader<'a>
type Item = Result<TableType, BinaryReaderError>
type IntoIter = SectionIteratorLimited<TableSectionReader<'a>>
source§impl<'a> IntoIterator for TagSectionReader<'a>
impl<'a> IntoIterator for TagSectionReader<'a>
type Item = Result<TagType, BinaryReaderError>
type IntoIter = SectionIteratorLimited<TagSectionReader<'a>>
source§impl<'a> IntoIterator for TypeSectionReader<'a>
impl<'a> IntoIterator for TypeSectionReader<'a>
type Item = Result<Type, BinaryReaderError>
type IntoIter = SectionIteratorLimited<TypeSectionReader<'a>>
source§impl<'a> IntoIterator for wasmparser::readers::core::code::LocalsReader<'a>
impl<'a> IntoIterator for wasmparser::readers::core::code::LocalsReader<'a>
type Item = Result<(u32, ValType), BinaryReaderError>
type IntoIter = LocalsIterator<'a>
source§impl<'a> IntoIterator for wasmparser::readers::core::operators::OperatorsReader<'a>
impl<'a> IntoIterator for wasmparser::readers::core::operators::OperatorsReader<'a>
type Item = Result<Operator<'a>, BinaryReaderError>
type IntoIter = OperatorsIterator<'a>
source§impl<'a, A> IntoIterator for &'a SmallVec<A>where
A: Array,
impl<'a, A> IntoIterator for &'a SmallVec<A>where
A: Array,
source§impl<'a, A> IntoIterator for &'a mut SmallVec<A>where
A: Array,
impl<'a, A> IntoIterator for &'a mut SmallVec<A>where
A: Array,
source§impl<'a, I> IntoIterator for &'a IntoChunks<I>
impl<'a, I> IntoIterator for &'a IntoChunks<I>
source§impl<'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).