Trait enum_iterator::IntoEnumIterator [−][src]
pub trait IntoEnumIterator: Sized { type Iterator: Iterator<Item = Self> + ExactSizeIterator + FusedIterator; fn into_enum_iter() -> Self::Iterator; }
Trait to iterate over the variants of a field-less enum.
Field-less (a.k.a. C-like) enums are enums whose variants don't have additional data.
When deriving this trait for an enum named Foo
, the associated type
Iterator
is a generated type named FooEnumIterator
. This generated
type has the same visibility as Foo
. Variants are yielded in the order
they are defined in the enum.
Example
#[macro_use] extern crate enum_iterator; use enum_iterator::IntoEnumIterator; #[derive(Clone, IntoEnumIterator, PartialEq)] enum Direction {North, South, West, East} fn main() { assert!(Direction::into_enum_iter().eq([Direction::North, Direction::South, Direction::West, Direction::East].iter() .cloned())); }
Associated Types
type Iterator: Iterator<Item = Self> + ExactSizeIterator + FusedIterator
Type of the iterator over the variants.
Required Methods
fn into_enum_iter() -> Self::Iterator
Returns an iterator over the variants.