Skip to main content

Hierarchical

Struct Hierarchical 

Source
pub struct Hierarchical<P, C> { /* private fields */ }
Expand description

Parent and child state machines with child-first event routing and retained shallow history.

Deactivating a child does not reset it. Reactivating it therefore resumes its previous state; reset_child explicitly replaces that history.

Implementations§

Source§

impl<P, C> Hierarchical<P, C>

Source

pub const fn new(parent: P, child: C) -> Self

Creates a hierarchy with an inactive child.

Source

pub const fn new_active(parent: P, child: C) -> Self

Creates a hierarchy whose child starts active.

Source

pub fn activate_child(&mut self)

Activates the child, preserving its previous state.

Source

pub fn deactivate_child(&mut self)

Deactivates the child while preserving shallow history.

Source

pub fn reset_child(&mut self, child: C)

Replaces the child and activates its new initial state.

Source

pub const fn child_is_active(&self) -> bool

Returns true when the child is active.

Source

pub fn parent(&self) -> &P

Returns the parent machine.

Source

pub fn parent_mut(&mut self) -> &mut P

Returns the parent machine mutably.

Source

pub fn child(&self) -> &C

Returns the child machine.

Source

pub fn child_mut(&mut self) -> &mut C

Returns the child machine mutably.

Source

pub fn process_event<E, FC, FP>( &mut self, event: E, child_dispatch: FC, parent_dispatch: FP, ) -> HierarchicalDispatch
where E: Clone, C: Terminated, FC: FnMut(&mut C, E) -> bool, FP: FnMut(&mut P, E) -> bool,

Routes an event to the active child first and bubbles unhandled events to the parent.

Source

pub fn process_event_with_completion<E, FC, FP, FT>( &mut self, event: E, child_dispatch: FC, parent_dispatch: FP, child_completion: FT, ) -> HierarchicalDispatch
where E: Clone, C: Terminated, FC: FnMut(&mut C, E) -> bool, FP: FnMut(&mut P, E) -> bool, FT: FnMut(&mut P) -> bool,

Routes an event like process_event and propagates child termination to a parent completion callback.

When the callback handles completion, the child is deactivated while retaining its state as shallow history.

Auto Trait Implementations§

§

impl<P, C> Freeze for Hierarchical<P, C>
where P: Freeze, C: Freeze,

§

impl<P, C> RefUnwindSafe for Hierarchical<P, C>

§

impl<P, C> Send for Hierarchical<P, C>
where P: Send, C: Send,

§

impl<P, C> Sync for Hierarchical<P, C>
where P: Sync, C: Sync,

§

impl<P, C> Unpin for Hierarchical<P, C>
where P: Unpin, C: Unpin,

§

impl<P, C> UnsafeUnpin for Hierarchical<P, C>
where P: UnsafeUnpin, C: UnsafeUnpin,

§

impl<P, C> UnwindSafe for Hierarchical<P, C>
where P: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.