Crate tinystate_derive

Crate tinystate_derive 

Source
Expand description

Derive macros for tinystate.

This crate provides procedural macros to automatically implement the States and Events traits for enum types, eliminating boilerplate code.

§Usage

Enable the derive feature in your Cargo.toml:

[dependencies]
tinystate = { version = "0.1", features = ["derive"] }

Then derive the traits on your enums:

use tinystate::{States, Events};

#[derive(States)]
enum TrafficLight {
    Red,
    Yellow,
    Green,
}

#[derive(Events)]
enum TrafficEvent {
    Timer,
    Emergency,
}

§Requirements

  • Both macros only work on enums with unit variants (no fields)
  • The first variant of a States enum becomes the default state

Derive Macros§

Events
Derives the Events trait for an enum.
States
Derives the States trait for an enum.