diff --git a/statig/src/awaitable/inner.rs b/statig/src/awaitable/inner.rs index a0b0d0f..f47bfa5 100644 --- a/statig/src/awaitable/inner.rs +++ b/statig/src/awaitable/inner.rs @@ -1,5 +1,6 @@ -use crate::awaitable::{IntoStateMachine, State, StateExt, Superstate}; +use crate::awaitable::{IntoStateMachine, StateExt}; use crate::Outcome; +use core::fmt::Debug; /// Private internal representation of a state machine that is used for the public types. pub(crate) struct Inner @@ -13,8 +14,6 @@ where impl Inner where M: IntoStateMachine, - M::State: State + 'static, - for<'sub> M::Superstate<'sub>: Superstate, { pub(crate) async fn init_with_context(&mut self, context: &mut M::Context<'_>) { let enter_levels = self.state.depth(); @@ -93,6 +92,19 @@ where { } +impl Debug for Inner +where + M: IntoStateMachine + Debug, + M::State: Debug, +{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Inner") + .field("shared_storage", &self.shared_storage) + .field("state", &self.state) + .finish() + } +} + #[cfg(feature = "serde")] impl serde::Serialize for Inner where diff --git a/statig/src/awaitable/into_state_machine.rs b/statig/src/awaitable/into_state_machine.rs index 9859408..6322feb 100644 --- a/statig/src/awaitable/into_state_machine.rs +++ b/statig/src/awaitable/into_state_machine.rs @@ -14,10 +14,10 @@ where type Context<'ctx>; /// Enumeration of the various states. - type State; + type State: crate::awaitable::State; /// Enumeration of the various superstates. - type Superstate<'sub> + type Superstate<'sub>: crate::awaitable::Superstate where Self::State: 'sub; diff --git a/statig/src/awaitable/state.rs b/statig/src/awaitable/state.rs index 3955e83..8aa19df 100644 --- a/statig/src/awaitable/state.rs +++ b/statig/src/awaitable/state.rs @@ -9,7 +9,6 @@ pub trait State where Self: Sized, M: IntoStateMachine, - for<'b> M::Superstate<'b>: Superstate, { /// Call the handler for the current state and let it handle the given event. fn call_handler( @@ -49,7 +48,6 @@ where pub trait StateExt: State where M: IntoStateMachine, - for<'b> M::Superstate<'b>: Superstate, { /// Check if two states are the same. fn same_state(lhs: &Self, rhs: &Self) -> bool { @@ -236,6 +234,5 @@ impl StateExt for T where Self: State, M: IntoStateMachine, - for<'b> M::Superstate<'b>: Superstate, { } diff --git a/statig/src/awaitable/state_machine.rs b/statig/src/awaitable/state_machine.rs index 546393c..ce91a2e 100644 --- a/statig/src/awaitable/state_machine.rs +++ b/statig/src/awaitable/state_machine.rs @@ -1,12 +1,9 @@ use core::fmt::Debug; -use crate::awaitable::{Inner, IntoStateMachine, State, Superstate}; +use crate::awaitable::{Inner, IntoStateMachine}; /// A state machine where the shared storage is of type `Self`. pub trait IntoStateMachineExt: IntoStateMachine -where - for<'sub> Self::Superstate<'sub>: Superstate, - Self::State: State, { /// Create a state machine that will be lazily initialized. fn state_machine(self) -> StateMachine @@ -36,9 +33,7 @@ where impl IntoStateMachineExt for T where - Self: IntoStateMachine, - for<'sub> Self::Superstate<'sub>: Superstate, - Self::State: State, + Self: IntoStateMachine { } @@ -54,8 +49,6 @@ where impl StateMachine where M: IntoStateMachine, - M::State: State + 'static, - for<'sub> M::Superstate<'sub>: Superstate, { /// Explicitly initialize the state machine. If the state machine is already initialized /// this is a no-op. @@ -289,6 +282,19 @@ where } } +impl Debug for StateMachine +where + M: IntoStateMachine + Debug, + M::State: Debug, +{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("StateMachine") + .field("inner", &self.inner) + .field("initialized", &self.initialized) + .finish() + } +} + #[cfg(feature = "serde")] #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] impl serde::Serialize for StateMachine @@ -346,8 +352,6 @@ where impl InitializedStateMachine where M: IntoStateMachine, - M::State: State + 'static, - for<'sub> M::Superstate<'sub>: Superstate, { /// Handle the given event. pub async fn handle(&mut self, event: &M::Event<'_>) @@ -590,8 +594,6 @@ where impl UninitializedStateMachine where M: IntoStateMachine, - M::State: State + 'static, - for<'sub> M::Superstate<'sub>: Superstate, { /// Initialize the state machine by executing all entry actions towards /// the initial state. diff --git a/statig/src/awaitable/superstate.rs b/statig/src/awaitable/superstate.rs index ef47fec..d043c22 100644 --- a/statig/src/awaitable/superstate.rs +++ b/statig/src/awaitable/superstate.rs @@ -47,11 +47,9 @@ where } /// Extensions for `Superstate` trait. -pub trait SuperstateExt: Superstate +pub trait SuperstateExt: Superstate + Sized where - Self: Sized, M: IntoStateMachine, - for<'sub> M::Superstate<'sub>: Superstate, { fn same_state(lhs: &M::Superstate<'_>, rhs: &M::Superstate<'_>) -> bool { use core::mem::{discriminant, transmute, Discriminant}; @@ -131,8 +129,7 @@ where impl SuperstateExt for T where - Self: Superstate, + T: Superstate, M: IntoStateMachine, - for<'sub> M::Superstate<'sub>: Superstate, { } diff --git a/statig/src/blocking/inner.rs b/statig/src/blocking/inner.rs index 3d3ada1..7687567 100644 --- a/statig/src/blocking/inner.rs +++ b/statig/src/blocking/inner.rs @@ -1,4 +1,5 @@ -use crate::blocking::{IntoStateMachine, State, StateExt, Superstate}; +use core::fmt::{Debug, Formatter}; +use crate::blocking::{IntoStateMachine, StateExt}; use crate::Outcome; /// Private internal representation of a state machine that is used for the public types. @@ -13,8 +14,6 @@ where impl Inner where M: IntoStateMachine, - M::State: State, - for<'sub> M::Superstate<'sub>: Superstate, { /// Initialize the state machine by executing all entry actions towards the initial state. pub(crate) fn init_with_context(&mut self, context: &mut M::Context<'_>) { @@ -89,6 +88,15 @@ where { } +impl Debug for Inner where M: IntoStateMachine + Debug, M::State: Debug { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Inner") + .field("shared_storage", &self.shared_storage) + .field("state", &self.state) + .finish() + } +} + #[cfg(feature = "serde")] impl serde::Serialize for Inner where diff --git a/statig/src/blocking/into_state_machine.rs b/statig/src/blocking/into_state_machine.rs index 1071746..ae0b204 100644 --- a/statig/src/blocking/into_state_machine.rs +++ b/statig/src/blocking/into_state_machine.rs @@ -12,10 +12,10 @@ where type Context<'ctx>; /// Enumeration of the various states. - type State; + type State: crate::blocking::State; /// Enumeration of the various superstates. - type Superstate<'sub> + type Superstate<'sub>: crate::blocking::Superstate where Self::State: 'sub; diff --git a/statig/src/blocking/state.rs b/statig/src/blocking/state.rs index 1907ec0..35f36f1 100644 --- a/statig/src/blocking/state.rs +++ b/statig/src/blocking/state.rs @@ -1,4 +1,4 @@ -use crate::blocking::{IntoStateMachine, Superstate, SuperstateExt}; +use crate::blocking::{IntoStateMachine, SuperstateExt}; use crate::{Outcome, StateOrSuperstate}; /// An enum that represents the leaf states of the state machine. @@ -30,11 +30,9 @@ where } /// Extensions for `State` trait. -pub trait StateExt<'a, M>: State +pub trait StateExt: State where M: IntoStateMachine, - M::State: 'a, - for<'b> M::Superstate<'b>: Superstate, { /// Check if two states are the same. fn same_state(lhs: &Self, rhs: &Self) -> bool { @@ -168,11 +166,9 @@ where } } -impl<'a, T, M> StateExt<'a, M> for T +impl StateExt for T where T: State, M: IntoStateMachine, - M::State: 'a, - for<'b> M::Superstate<'b>: Superstate, { } diff --git a/statig/src/blocking/state_machine.rs b/statig/src/blocking/state_machine.rs index e508361..c210c81 100644 --- a/statig/src/blocking/state_machine.rs +++ b/statig/src/blocking/state_machine.rs @@ -1,11 +1,9 @@ use core::fmt::Debug; -use crate::blocking::{Inner, IntoStateMachine, State, Superstate}; +use crate::blocking::{Inner, IntoStateMachine}; /// A state machine where the shared storage is of type `Self`. pub trait IntoStateMachineExt: IntoStateMachine -where - Self::State: State, { /// Create a state machine that will be lazily initialized. fn state_machine(self) -> StateMachine @@ -35,8 +33,7 @@ where impl IntoStateMachineExt for T where - T: IntoStateMachine, - Self::State: State, + T: IntoStateMachine { } @@ -52,8 +49,6 @@ where impl StateMachine where M: IntoStateMachine, - M::State: State, - for<'sub> M::Superstate<'sub>: Superstate, { /// Explicitly initialize the state machine. If the state machine is already initialized /// this is a no-op. @@ -283,6 +278,19 @@ where } } +impl Debug for StateMachine +where + M: IntoStateMachine + Debug, + M::State: Debug, +{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("StateMachine") + .field("inner", &self.inner) + .field("initialized", &self.initialized) + .finish() + } +} + #[cfg(feature = "serde")] #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] impl serde::Serialize for StateMachine @@ -340,13 +348,11 @@ where impl InitializedStateMachine where M: IntoStateMachine, - M::State: State, { /// Handle the given event. pub fn handle(&mut self, event: &M::Event<'_>) where for<'ctx> M: IntoStateMachine = ()>, - for<'sub> M::Superstate<'sub>: Superstate, { self.handle_with_context(event, &mut ()); } @@ -355,7 +361,6 @@ where pub fn handle_with_context(&mut self, event: &M::Event<'_>, context: &mut M::Context<'_>) where M: IntoStateMachine, - for<'sub> M::Superstate<'sub>: Superstate, { self.inner.handle_with_context(event, context); } @@ -364,7 +369,6 @@ where pub fn step(&mut self) where for<'evt, 'ctx> M: IntoStateMachine = (), Context<'ctx> = ()>, - for<'sub> M::Superstate<'sub>: Superstate, { self.handle(&()); } @@ -373,7 +377,6 @@ where pub fn step_with_context(&mut self, context: &mut M::Context<'_>) where for<'evt> M: IntoStateMachine = ()>, - for<'sub> M::Superstate<'sub>: Superstate, { self.handle_with_context(&(), context); } @@ -578,7 +581,6 @@ where impl UninitializedStateMachine where M: IntoStateMachine, - M::State: State, { /// Initialize the state machine by executing all entry actions towards /// the initial state. @@ -607,7 +609,6 @@ where pub fn init(self) -> InitializedStateMachine where for<'ctx> M: IntoStateMachine = ()>, - for<'sub> M::Superstate<'sub>: Superstate, { let mut state_machine = InitializedStateMachine { inner: self.inner }; state_machine.inner.init_with_context(&mut ()); @@ -639,8 +640,6 @@ where /// let initialized_state_machine = uninitialized_state_machine.init(); /// ``` pub fn init_with_context(self, context: &mut M::Context<'_>) -> InitializedStateMachine - where - for<'sub> M::Superstate<'sub>: Superstate, { let mut state_machine = InitializedStateMachine { inner: self.inner }; state_machine.inner.init_with_context(context); diff --git a/statig/src/blocking/superstate.rs b/statig/src/blocking/superstate.rs index 469774d..30057c7 100644 --- a/statig/src/blocking/superstate.rs +++ b/statig/src/blocking/superstate.rs @@ -34,12 +34,9 @@ where } /// Extensions for `Superstate` trait. -pub trait SuperstateExt<'a, M>: Superstate +pub trait SuperstateExt: Superstate + Sized where M: IntoStateMachine, - Self: Sized, - M::State: 'a, - for<'b> M::Superstate<'b>: Superstate, { fn same_state(lhs: &M::Superstate<'_>, rhs: &M::Superstate<'_>) -> bool { use core::mem::{discriminant, transmute, Discriminant}; @@ -185,11 +182,9 @@ where } } -impl<'a, T, M> SuperstateExt<'a, M> for T +impl SuperstateExt for T where T: Superstate, M: IntoStateMachine, - M::State: 'a, - for<'b> M::Superstate<'b>: Superstate, { }