Expand description
state-shift is a procedural macro crate designed to:
- hide away the complexities come with type-state pattern,
- make your code more readable and maintainable,
- and still benefit from the power of type-state pattern.
Type-state is a design pattern that leverages the type system to enforce valid states and transitions at compile time. This crate provides attribute macros to transform structures and methods into type-safe stateful components, ensuring that methods are only callable in valid states, and enforcing transitions between them.
Macros:
#[require]: Enforces that a method can only be called when the provided state is active..#[switch_to]: Modifies the return type of methods to switch between states.#[states]: Defines the valid states for a given type and generates corresponding marker structs and trait implementations.#[type_state]: Transforms the struct into type-state compatible form, using state slots and default states.
Attribute Macrosยง
- Denotes which state is required for this method to be called.
- Denotes which states will be used for the type-state pattern.
- Denotes to which state will the object transition into after this method
- Turns your struct into type-state compatible version.