state_shift

Attribute Macro states

source
#[states]
Expand description

Denotes which states will be used for the type-state pattern.

Usage: #[states(State1, State2, ...)]

What it does:

  • defines the set of states that a type can transition between,
  • generates marker structs for these states
  • seals these traits and structs with TypeStateProtector trait for each state,
  • provides the necessary struct_name information to #[require] macro

Also:

  • consumes #[require] macro and does the things mentioned in #[require] macro’s inline docs, which are:
  • generates a specific impl block for each method,
  • adds the required types and generics to the generated impl blocks,
  • adds the hidden _state field to the Self { } struct, so you don’t have to worry about anything regarding type-state-pattern