Skip to main content

Iterable

Trait Iterable 

Source
pub trait Iterable: Sized {
    type Iterator: Iterator<Item = Self> + Clone + DoubleEndedIterator + ExactSizeIterator + FusedIterator;

    // Required method
    fn iter() -> Self::Iterator;
}
Expand description

This trait designates that an Enum can be iterated over. It can be auto generated using the EnumIter derive macro.

§Example

// You need to bring the type into scope to use it!!!
use strum::{EnumIter, IntoEnumIterator};

#[derive(EnumIter, Debug)]
enum Color {
    Red,
    Green { range: usize },
    Blue(usize),
    Yellow,
}

// Iterate over the items in an enum and perform some function on them.
fn generic_iterator<E, F>(pred: F)
where
    E: IntoEnumIterator,
    F: Fn(E),
{
    for e in E::iter() {
        pred(e)
    }
}

generic_iterator::<Color, _>(|color| println!("{:?}", color));

Required Associated Types§

Required Methods§

Source

fn iter() -> Self::Iterator

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl IntoEnumIterator for Column

Source§

impl IntoEnumIterator for PrimaryKey

Source§

impl IntoEnumIterator for Relation

Implementors§