typestate 0.1.2-alpha

macro_rules! to build typestates
Documentation

Typestate

Currently, this crate exports a single macro: typestate!.

The macro defines a small DSL to generate typestate-ready structures.

Syntax

The macro is defined by the following (pseudo) syntax:

(limited|strict)? $visibility? $struct_name
$(<$state_name $(:$state_trait_bound)?>)?
($($strict_mod_name::)? $strict_mod_trait)?
[$($typestate),+]
{$($struct_field:$struct_type),+}

Usage Examples

Example of unconstrained typestate:

typestate!(
    Drone [Idle, Hovering, Flying] {
        x: f32,
        y: f32
    }
);

Example of a limited typestate:

typestate!(
    limited Drone [Idle, Hovering, Flying] {
        x: f32,
        y: f32
    }
);

Example of a strict typestate:

typestate!(
    strict Drone [Idle, Hovering, Flying] {
        x: f32,
        y: f32
    }
);