pub mod transition;
pub use transition::Transition;
#[macro_export]
macro_rules! define_state_machine {
($trait_name:ident { $($state:ident),+ $(,)? }) => {
mod private {
pub trait Sealed {}
}
pub trait $trait_name: private::Sealed {}
$(
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct $state;
impl private::Sealed for $state {}
impl $trait_name for $state {}
)+
};
}
#[macro_export]
macro_rules! define_typestate {
($name:ident<$param:ident: $bound:ident> { $($field:ident: $ftype:ty),* $(,)? }) => {
pub struct $name<$param: $bound> {
$( pub $field: $ftype, )*
_state: ::std::marker::PhantomData<$param>,
}
impl<$param: $bound> $name<$param> {
pub fn new($($field: $ftype),*) -> Self {
Self { $($field,)* _state: ::std::marker::PhantomData }
}
pub fn data(&self) -> ($(&$ftype,)*) {
($(&self.$field,)*)
}
pub fn into_data(self) -> ($($ftype,)*) {
($(self.$field,)*)
}
}
};
}