Skip to main content

EnumStep

Derive Macro EnumStep 

Source
#[derive(EnumStep)]
Expand description

Implements [enum_traits::Step].

The next and previous functions are computed by using the variants of the enum in their defined order.

§Requirements

  • The derived item is an enum.
  • The enum’s variants are all unit variants.

§Example using derive

use enum_traits_macros::*;

#[derive(EnumStep)]
enum Enum{A,B,C,D}

§Expanded example

use enum_traits::*;

enum Enum{A,B,C,D}

impl Step for Enum{
	fn next(self) -> Option<Self>{match self{
		Enum::A => Some(Enum::B),
		Enum::B => Some(Enum::C),
		Enum::C => Some(Enum::D),
		Enum::D => None,
	}}
	fn previous(self) -> Option<Self>{match self{
		Enum::A => None,
		Enum::B => Some(Enum::A),
		Enum::C => Some(Enum::B),
		Enum::D => Some(Enum::C),
	}}
}