devela::_dep::_std::iter

Trait IntoIterator

1.0.0 · Source
pub trait IntoIterator {
    type Item;
    type IntoIter: Iterator<Item = Self::Item>;

    // Required method
    fn into_iter(self) -> Self::IntoIter;
}
Available on crate feature std only.
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§

1.0.0 · Source

type Item

The type of the elements being iterated over.

1.0.0 · Source

type IntoIter: Iterator<Item = Self::Item>

Which kind of iterator are we turning this into?

Required Methods§

1.0.0 · Source

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§

§

impl IntoIterator for KeyEventState

§

impl IntoIterator for KeyModifiers

§

impl IntoIterator for KeyboardEnhancementFlags

Source§

impl IntoIterator for Array

Source§

impl IntoIterator for Iterator

§

impl IntoIterator for devela::_dep::rustix::event::epoll::CreateFlags

§

impl IntoIterator for EventfdFlags

§

impl IntoIterator for PollFlags

§

impl IntoIterator for devela::_dep::rustix::fs::inotify::CreateFlags

§

impl IntoIterator for ReadFlags

§

impl IntoIterator for WatchFlags

§

impl IntoIterator for Access

§

type Item = Access

§

type IntoIter = Iter<Access>

§

impl IntoIterator for AtFlags

§

type Item = AtFlags

§

type IntoIter = Iter<AtFlags>

§

impl IntoIterator for FallocateFlags

§

impl IntoIterator for FdFlags

§

type Item = FdFlags

§

type IntoIter = Iter<FdFlags>

§

impl IntoIterator for IFlags

§

type Item = IFlags

§

type IntoIter = Iter<IFlags>

§

impl IntoIterator for MemfdFlags

§

impl IntoIterator for Mode

§

type Item = Mode

§

type IntoIter = Iter<Mode>

§

impl IntoIterator for MountFlags

§

impl IntoIterator for MountPropagationFlags

§

impl IntoIterator for OFlags

§

type Item = OFlags

§

type IntoIter = Iter<OFlags>

§

impl IntoIterator for RenameFlags

§

impl IntoIterator for ResolveFlags

§

impl IntoIterator for SealFlags

§

impl IntoIterator for StatVfsMountFlags

§

impl IntoIterator for StatxFlags

§

impl IntoIterator for UnmountFlags

§

impl IntoIterator for XattrFlags

§

impl IntoIterator for DupFlags

§

type Item = DupFlags

§

type IntoIter = Iter<DupFlags>

§

impl IntoIterator for ReadWriteFlags

§

impl IntoIterator for EventFlags

§

impl IntoIterator for IoringAcceptFlags

§

impl IntoIterator for IoringAsyncCancelFlags

§

impl IntoIterator for IoringCqFlags

§

impl IntoIterator for IoringCqeFlags

§

impl IntoIterator for IoringEnterFlags

§

impl IntoIterator for IoringFeatureFlags

§

impl IntoIterator for IoringFsyncFlags

§

impl IntoIterator for IoringMsgringFlags

§

impl IntoIterator for IoringOpFlags

§

impl IntoIterator for IoringPollFlags

§

impl IntoIterator for IoringRecvFlags

§

impl IntoIterator for IoringRegisterFlags

§

impl IntoIterator for IoringRsrcFlags

§

impl IntoIterator for IoringSendFlags

§

impl IntoIterator for IoringSetupFlags

§

impl IntoIterator for IoringSqFlags

§

impl IntoIterator for IoringSqeFlags

§

impl IntoIterator for IoringTimeoutFlags

§

impl IntoIterator for RecvFlags

§

impl IntoIterator for RecvmsgOutFlags

§

impl IntoIterator for SendFlags

§

impl IntoIterator for SocketFlags

§

impl IntoIterator for devela::_dep::rustix::io_uring::SpliceFlags

§

impl IntoIterator for MapFlags

§

type Item = MapFlags

§

type IntoIter = Iter<MapFlags>

§

impl IntoIterator for MlockAllFlags

§

impl IntoIterator for MlockFlags

§

impl IntoIterator for MprotectFlags

§

impl IntoIterator for MremapFlags

§

impl IntoIterator for MsyncFlags

§

impl IntoIterator for ProtFlags

§

impl IntoIterator for UserfaultfdFlags

§

impl IntoIterator for FsMountFlags

§

impl IntoIterator for FsOpenFlags

§

impl IntoIterator for FsPickFlags

§

impl IntoIterator for MountAttrFlags

§

impl IntoIterator for MoveMountFlags

§

impl IntoIterator for OpenTreeFlags

§

impl IntoIterator for SockaddrXdpFlags

§

impl IntoIterator for XdpDescOptions

§

impl IntoIterator for XdpOptionsFlags

§

impl IntoIterator for XdpRingFlags

§

impl IntoIterator for XdpUmemRegFlags

§

impl IntoIterator for PipeFlags

§

impl IntoIterator for devela::_dep::rustix::pipe::SpliceFlags

§

impl IntoIterator for FloatingPointEmulationControl

§

impl IntoIterator for FloatingPointExceptionMode

§

impl IntoIterator for MembarrierQuery

§

impl IntoIterator for PidfdFlags

§

impl IntoIterator for PidfdGetfdFlags

§

impl IntoIterator for SpeculationFeatureControl

§

impl IntoIterator for SpeculationFeatureState

§

impl IntoIterator for UnalignedAccessControl

§

impl IntoIterator for WaitOptions

§

impl IntoIterator for WaitidOptions

§

impl IntoIterator for OpenptFlags

§

impl IntoIterator for GetRandomFlags

§

impl IntoIterator for ShmOFlags

§

impl IntoIterator for ControlModes

§

impl IntoIterator for InputModes

§

impl IntoIterator for LocalModes

§

impl IntoIterator for OutputModes

§

impl IntoIterator for CapabilitiesSecureBits

§

impl IntoIterator for CapabilityFlags

§

impl IntoIterator for devela::_dep::rustix::thread::FutexFlags

§

type Item = Flags

§

type IntoIter = Iter<Flags>

§

impl IntoIterator for TaggedAddressMode

§

impl IntoIterator for ThreadNameSpaceType

§

impl IntoIterator for UnshareFlags

§

impl IntoIterator for TimerfdFlags

§

impl IntoIterator for TimerfdTimerFlags

§

impl IntoIterator for Bytes

§

type Item = u8

§

type IntoIter = IntoIter<Bytes>

§

impl IntoIterator for BytesMut

§

type Item = u8

§

type IntoIter = IntoIter<BytesMut>

§

impl IntoIterator for Flags

§

type Item = Flags

§

type IntoIter = Iter<Flags>

§

impl IntoIterator for PortCap

§

type Item = PortCap

§

type IntoIter = Iter<PortCap>

§

impl IntoIterator for PortType

§

type Item = PortType

§

type IntoIter = Iter<PortType>

§

impl IntoIterator for Remove

§

type Item = Remove

§

type IntoIter = Iter<Remove>

1.6.0 · Source§

impl<'a> IntoIterator for &'a Path

1.6.0 · Source§

impl<'a> IntoIterator for &'a PathBuf

Source§

impl<'a> IntoIterator for &'a Iterator

§

impl<'a> IntoIterator for &'a EventVec

§

type IntoIter = Iter<'a>

§

type Item = Event

§

impl<'a> IntoIterator for &'a Components

§

type Item = &'a Component

§

type IntoIter = Iter<'a, Component>

§

impl<'a> IntoIterator for &'a Disks

§

type Item = &'a Disk

§

type IntoIter = Iter<'a, Disk>

§

impl<'a> IntoIterator for &'a Groups

§

type Item = &'a Group

§

type IntoIter = Iter<'a, Group>

§

impl<'a> IntoIterator for &'a Networks

§

type Item = (&'a String, &'a NetworkData)

§

type IntoIter = Iter<'a, String, NetworkData>

§

impl<'a> IntoIterator for &'a Users

§

type Item = &'a User

§

type IntoIter = Iter<'a, User>

§

impl<'a> IntoIterator for &'a FieldSet

1.10.0 · Source§

impl<'a> IntoIterator for &'a UnixListener

§

impl<'a> IntoIterator for &'a Bytes

§

type Item = &'a u8

§

type IntoIter = Iter<'a, u8>

§

impl<'a> IntoIterator for &'a BytesMut

§

type Item = &'a u8

§

type IntoIter = Iter<'a, u8>

§

impl<'a> IntoIterator for &'a Events

§

type Item = &'a Event

§

type IntoIter = Iter<'a>

§

impl<'a> IntoIterator for &'a mut Components

§

type Item = &'a mut Component

§

type IntoIter = IterMut<'a, Component>

§

impl<'a> IntoIterator for &'a mut Disks

§

type Item = &'a mut Disk

§

type IntoIter = IterMut<'a, Disk>

§

impl<'a> IntoIterator for &'a mut Groups

§

type Item = &'a mut Group

§

type IntoIter = IterMut<'a, Group>

§

impl<'a> IntoIterator for &'a mut Users

§

type Item = &'a mut User

§

type IntoIter = IterMut<'a, User>

§

impl<'a, 'bump, T> IntoIterator for &'a devela::_dep::bumpalo::collections::Vec<'bump, T>

§

type Item = &'a T

§

type IntoIter = Iter<'a, T>

§

impl<'a, 'bump, T> IntoIterator for &'a mut devela::_dep::bumpalo::collections::Vec<'bump, T>

§

type Item = &'a mut T

§

type IntoIter = IterMut<'a, T>

§

impl<'a, A> IntoIterator for &'a SmallVec<A>
where A: Array,

§

type IntoIter = Iter<'a, <A as Array>::Item>

§

type Item = &'a <A as Array>::Item

§

impl<'a, A> IntoIterator for &'a mut SmallVec<A>
where A: Array,

§

type IntoIter = IterMut<'a, <A as Array>::Item>

§

type Item = &'a mut <A as Array>::Item

§

impl<'a, E> IntoIterator for &'a mut SignalsInfo<E>
where E: Exfiltrator,

§

type Item = <E as Exfiltrator>::Output

§

type IntoIter = Forever<'a, E>

1.80.0 · Source§

impl<'a, I, A> IntoIterator for &'a Box<[I], A>
where A: Allocator,

1.80.0 · Source§

impl<'a, I, A> IntoIterator for &'a mut Box<[I], A>
where A: Allocator,

1.0.0 · Source§

impl<'a, K, V, A> IntoIterator for &'a BTreeMap<K, V, A>
where A: Allocator + Clone,

Source§

type Item = (&'a K, &'a V)

Source§

type IntoIter = Iter<'a, K, V>

1.0.0 · Source§

impl<'a, K, V, A> IntoIterator for &'a mut BTreeMap<K, V, A>
where A: Allocator + Clone,

1.0.0 · Source§

impl<'a, K, V, S> IntoIterator for &'a devela::_dep::_std::collections::HashMap<K, V, S>

Source§

type Item = (&'a K, &'a V)

Source§

type IntoIter = Iter<'a, K, V>

1.0.0 · Source§

impl<'a, K, V, S> IntoIterator for &'a mut devela::_dep::_std::collections::HashMap<K, V, S>

§

impl<'a, K, V, S, A> IntoIterator for &'a devela::all::HashMap<K, V, S, A>
where A: Allocator,

§

type Item = (&'a K, &'a V)

§

type IntoIter = Iter<'a, K, V>

§

impl<'a, K, V, S, A> IntoIterator for &'a mut devela::all::HashMap<K, V, S, A>
where A: Allocator,

§

type Item = (&'a K, &'a mut V)

§

type IntoIter = IterMut<'a, K, V>

1.4.0 · Source§

impl<'a, T> IntoIterator for &'a Option<T>

§

impl<'a, T> IntoIterator for &'a ArchivedOption<T>

1.0.0 · Source§

impl<'a, T> IntoIterator for &'a [T]

Source§

impl<'a, T> IntoIterator for &'a ConstList<'a, T>

Source§

impl<'a, T> IntoIterator for &'a devela::_dep::_std::sync::mpmc::Receiver<T>

Source§

type Item = T

Source§

type IntoIter = Iter<'a, T>

1.1.0 · Source§

impl<'a, T> IntoIterator for &'a devela::_dep::_std::sync::mpsc::Receiver<T>

Source§

type Item = T

Source§

type IntoIter = Iter<'a, T>

§

impl<'a, T> IntoIterator for &'a Arena<T>

§

type Item = (Key, &'a T)

§

type IntoIter = Iter<'a, T>

1.4.0 · Source§

impl<'a, T> IntoIterator for &'a mut Option<T>

§

impl<'a, T> IntoIterator for &'a mut ArchivedOption<T>

1.0.0 · Source§

impl<'a, T> IntoIterator for &'a mut [T]

§

impl<'a, T> IntoIterator for &'a mut Arena<T>

§

type Item = (Key, &'a mut T)

§

type IntoIter = IterMut<'a, T>

§

impl<'a, T> IntoIterator for Seal<'a, ArchivedOption<T>>

§

type Item = Seal<'a, T>

§

type IntoIter = Iter<Seal<'a, T>>

§

impl<'a, T> IntoIterator for ReadChunk<'a, T>

§

type Item = T

§

type IntoIter = ReadChunkIntoIter<'a, T>

1.0.0 · Source§

impl<'a, T, A> IntoIterator for &'a BTreeSet<T, A>
where A: Allocator + Clone,

1.0.0 · Source§

impl<'a, T, A> IntoIterator for &'a BinaryHeap<T, A>
where A: Allocator,

1.0.0 · Source§

impl<'a, T, A> IntoIterator for &'a LinkedList<T, A>
where A: Allocator,

1.0.0 · Source§

impl<'a, T, A> IntoIterator for &'a devela::all::Vec<T, A>
where A: Allocator,

1.0.0 · Source§

impl<'a, T, A> IntoIterator for &'a VecDeque<T, A>
where A: Allocator,

§

impl<'a, T, A> IntoIterator for &'a HashTable<T, A>
where A: Allocator,

§

type Item = &'a T

§

type IntoIter = Iter<'a, T>

1.0.0 · Source§

impl<'a, T, A> IntoIterator for &'a mut LinkedList<T, A>
where A: Allocator,

1.0.0 · Source§

impl<'a, T, A> IntoIterator for &'a mut devela::all::Vec<T, A>
where A: Allocator,

1.0.0 · Source§

impl<'a, T, A> IntoIterator for &'a mut VecDeque<T, A>
where A: Allocator,

§

impl<'a, T, A> IntoIterator for &'a mut HashTable<T, A>
where A: Allocator,

§

type Item = &'a mut T

§

type IntoIter = IterMut<'a, T>

1.4.0 · Source§

impl<'a, T, E> IntoIterator for &'a Result<T, E>

1.4.0 · Source§

impl<'a, T, E> IntoIterator for &'a mut Result<T, E>

1.0.0 · Source§

impl<'a, T, S> IntoIterator for &'a devela::_dep::_std::collections::HashSet<T, S>

§

impl<'a, T, S, A> IntoIterator for &'a devela::all::HashSet<T, S, A>
where A: Allocator,

§

type Item = &'a T

§

type IntoIter = Iter<'a, T>

Source§

impl<'a, T, const CAP: usize> IntoIterator for &'a 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 {
    // ...
}
Source§

impl<'a, T, const CAP: usize> IntoIterator for &'a mut 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 {
    // ...
}
1.0.0 · Source§

impl<'a, T, const N: usize> IntoIterator for &'a [T; N]

1.0.0 · Source§

impl<'a, T, const N: usize> IntoIterator for &'a mut [T; N]

§

impl<'bump, T> IntoIterator for devela::_dep::bumpalo::collections::Vec<'bump, T>
where T: 'bump,

§

type Item = T

§

type IntoIter = IntoIter<'bump, T>

§

impl<'py> IntoIterator for &Bound<'py, PyDict>

§

type Item = (Bound<'py, PyAny>, Bound<'py, PyAny>)

§

type IntoIter = BoundDictIterator<'py>

§

impl<'py> IntoIterator for &Bound<'py, PyFrozenSet>

§

impl<'py> IntoIterator for &Bound<'py, PyIterator>

§

impl<'py> IntoIterator for &Bound<'py, PyList>

§

impl<'py> IntoIterator for &Bound<'py, PySet>

§

type Item = Bound<'py, PyAny>

§

type IntoIter = BoundSetIterator<'py>

§

impl<'py> IntoIterator for &Bound<'py, PyTuple>

§

impl<'py> IntoIterator for Bound<'py, PyDict>

§

type Item = (Bound<'py, PyAny>, Bound<'py, PyAny>)

§

type IntoIter = BoundDictIterator<'py>

§

impl<'py> IntoIterator for Bound<'py, PyFrozenSet>

§

impl<'py> IntoIterator for Bound<'py, PyList>

§

impl<'py> IntoIterator for Bound<'py, PySet>

§

type Item = Bound<'py, PyAny>

§

type IntoIter = BoundSetIterator<'py>

§

impl<'py> IntoIterator for Bound<'py, PyTuple>

Source§

impl<A> IntoIterator for Range<A>
where A: Step,

Source§

impl<A> IntoIterator for RangeFrom<A>
where A: Step,

Source§

impl<A> IntoIterator for RangeInclusive<A>
where A: Step,

§

impl<A> IntoIterator for SmallVec<A>
where A: Array,

§

type IntoIter = IntoIter<A>

§

type Item = <A as Array>::Item

1.0.0 · Source§

impl<I> IntoIterator for I
where I: Iterator,

1.80.0 · Source§

impl<I, A> IntoIterator for Box<[I], A>
where A: Allocator,

1.0.0 · Source§

impl<K, V, A> IntoIterator for BTreeMap<K, V, A>
where A: Allocator + Clone,

1.0.0 · Source§

impl<K, V, S> IntoIterator for devela::_dep::_std::collections::HashMap<K, V, S>

§

impl<K, V, S, A> IntoIterator for devela::all::HashMap<K, V, S, A>
where A: Allocator,

§

type Item = (K, V)

§

type IntoIter = IntoIter<K, V, A>

1.0.0 · Source§

impl<T> IntoIterator for Option<T>

Source§

impl<T> IntoIterator for devela::_dep::_std::sync::mpmc::Receiver<T>

1.1.0 · Source§

impl<T> IntoIterator for devela::_dep::_std::sync::mpsc::Receiver<T>

1.0.0 · Source§

impl<T, A> IntoIterator for BTreeSet<T, A>
where A: Allocator + Clone,

1.0.0 · Source§

impl<T, A> IntoIterator for BinaryHeap<T, A>
where A: Allocator,

1.0.0 · Source§

impl<T, A> IntoIterator for LinkedList<T, A>
where A: Allocator,

1.0.0 · Source§

impl<T, A> IntoIterator for devela::all::Vec<T, A>
where A: Allocator,

1.0.0 · Source§

impl<T, A> IntoIterator for VecDeque<T, A>
where A: Allocator,

§

impl<T, A> IntoIterator for HashTable<T, A>
where A: Allocator,

§

type Item = T

§

type IntoIter = IntoIter<T, A>

1.0.0 · Source§

impl<T, E> IntoIterator for Result<T, E>

1.0.0 · Source§

impl<T, S> IntoIterator for devela::_dep::_std::collections::HashSet<T, S>

§

impl<T, S, A> IntoIterator for devela::all::HashSet<T, S, A>
where A: Allocator,

§

type Item = T

§

type IntoIter = IntoIter<T, A>

§

impl<T, U> IntoIterator for Chain<T, U>
where T: Buf, U: Buf,

§

type Item = u8

§

type IntoIter = IntoIter<Chain<T, U>>

Source§

impl<T, const CAP: usize> IntoIterator for 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]) {
    // ...
}
Source§

type Item = T

Source§

type IntoIter = IntoIter<T, CAP>

1.53.0 · Source§

impl<T, const N: usize> IntoIterator for [T; N]