pub struct Machine<C, E> { /* private fields */ }Expand description
A compiled machine definition. Create actors from it with
crate::Actor::start; one machine can be shared by many actors.
Implementations§
Source§impl<C, E> Machine<C, E>where
C: DeserializeOwned + 'static,
E: EventType + 'static,
impl<C, E> Machine<C, E>where
C: DeserializeOwned + 'static,
E: EventType + 'static,
Sourcepub fn from_json(
json: &Value,
registry: &Registry<C, E>,
) -> Result<Self, LoadError>
pub fn from_json( json: &Value, registry: &Registry<C, E>, ) -> Result<Self, LoadError>
Compiles a MachineJSON definition. Every referenced guard, action and
named delay must be in registry (or defined in the JSON itself). A
macrostep is unbounded unless the definition sets
options.maxIterations, as machineToJSON writes it.
Sourcepub fn references(json: &Value) -> Result<References, LoadError>
pub fn references(json: &Value) -> Result<References, LoadError>
Validates a definition and lists the guards, actions, delays and actors it needs from the host (everything not defined in the JSON or built in), with their JSON paths and params. Used by code generation.
Trait Implementations§
Source§impl<C, E> Debug for Machine<C, E>
The machine’s id, version and size; its implementations are closures.
impl<C, E> Debug for Machine<C, E>
The machine’s id, version and size; its implementations are closures.
Source§impl<C, E> Logic for Machine<C, E>
impl<C, E> Logic for Machine<C, E>
Source§fn logic_id(&self) -> Option<String>
fn logic_id(&self) -> Option<String>
The logic’s own id (a machine’s
id), used for the root actor.Source§fn initial_transition(
&self,
input: Option<&Value>,
cx: &mut dyn Context,
) -> Result<Transition, SystemError>
fn initial_transition( &self, input: Option<&Value>, cx: &mut dyn Context, ) -> Result<Transition, SystemError>
The initial snapshot and effects for
input.Source§fn transition(
&self,
snapshot: &mut Box<dyn AnySnapshot>,
event: Value,
cx: &mut dyn Context,
) -> Result<Vec<Effect>, SystemError>
fn transition( &self, snapshot: &mut Box<dyn AnySnapshot>, event: Value, cx: &mut dyn Context, ) -> Result<Vec<Effect>, SystemError>
Transitions
snapshot (in place, or by replacing it) for event
and returns the effects. On error the snapshot stays with its actor.Source§fn check(
&self,
snapshot: &dyn AnySnapshot,
event: &Value,
cx: &mut dyn Context,
) -> Result<TransitionCheck, SystemError>
fn check( &self, snapshot: &dyn AnySnapshot, event: &Value, cx: &mut dyn Context, ) -> Result<TransitionCheck, SystemError>
XState’s
snapshot.check(event): what snapshot would do with
event, which it does not take. Guards and transition functions run
as a transition’s selection runs them, actions do not, and the
snapshot is left as it is. A guard or a function that throws fails
the check. Only a machine’s snapshot checks an event.Source§fn handles(
&self,
snapshot: &dyn AnySnapshot,
event: &Value,
cx: &mut dyn Context,
) -> Result<bool, SystemError>
fn handles( &self, snapshot: &dyn AnySnapshot, event: &Value, cx: &mut dyn Context, ) -> Result<bool, SystemError>
Whether
snapshot selects a transition of event, which it does not
take: any transition, also one with nothing to do or one that
rejects the event, as XState’s !isUnhandled(transition(...)).
Guards and transition functions run as in Logic::check. Only a
machine’s snapshot selects transitions.Source§fn timer_transition(
&self,
snapshot: &mut Box<dyn AnySnapshot>,
key: TimerKey,
occurrence: Option<u64>,
cx: &mut dyn Context,
) -> Result<Vec<Effect>, SystemError>
fn timer_transition( &self, snapshot: &mut Box<dyn AnySnapshot>, key: TimerKey, occurrence: Option<u64>, cx: &mut dyn Context, ) -> Result<Vec<Effect>, SystemError>
Logic::transition for a fired machine timer, { type: "xstate.timer", ...key, occurrence }; logic that keeps timers can
take the key without the event.Source§fn snapshot_data(&self, snapshot: &dyn AnySnapshot) -> Value
fn snapshot_data(&self, snapshot: &dyn AnySnapshot) -> Value
XState’s snapshot data, as stored in a system snapshot.
Source§fn snapshot_serialize<'a>(
&'a self,
snapshot: &'a dyn AnySnapshot,
compact: bool,
) -> Box<dyn Serialize + 'a>
fn snapshot_serialize<'a>( &'a self, snapshot: &'a dyn AnySnapshot, compact: bool, ) -> Box<dyn Serialize + 'a>
Logic::snapshot_data as something that serializes to the same
data, so a snapshot can be written without building it as a Value.
With compact, fields that Logic::restore rebuilds identically
when they are missing may be left out (see System::compact_view).Source§fn restore(&self, data: &Value) -> Result<Box<dyn AnySnapshot>, SystemError>
fn restore(&self, data: &Value) -> Result<Box<dyn AnySnapshot>, SystemError>
Rebuilds a snapshot from its data.
Source§fn is_internal_event_type(&self, event_type: &str) -> bool
fn is_internal_event_type(&self, event_type: &str) -> bool
Event types only the actor itself may send.
Source§fn actor_sources(&self) -> Vec<(String, Arc<dyn Logic>)>
fn actor_sources(&self) -> Vec<(String, Arc<dyn Logic>)>
Named actor logic this logic can invoke (
sources.actors), in order.Source§fn execution_error_event(
&self,
snapshot: &dyn AnySnapshot,
error: &Value,
) -> Option<Value>
fn execution_error_event( &self, snapshot: &dyn AnySnapshot, error: &Value, ) -> Option<Value>
XState’s
getExecutionErrorEvent: the event an actor of this logic
recovers from an execution error with (error as XState persists
it), when
snapshot can (a machine with an active state that declares
onError).Auto Trait Implementations§
impl<C, E> !RefUnwindSafe for Machine<C, E>
impl<C, E> !UnwindSafe for Machine<C, E>
impl<C, E> Forget for Machine<C, E>
impl<C, E> Freeze for Machine<C, E>where
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<TreeNode>: Freeze,
PhantomData<TreeTransition>: Freeze,
PhantomData<NodeData>: Freeze,
PhantomData<TransitionData>: Freeze,
PhantomData<Box<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>>: Freeze,
PhantomData<CustomAction>: Freeze,
PhantomData<(String, Arc<dyn Logic>)>: Freeze,
PhantomData<Box<dyn Fn(&C, &Ev<E>) -> Result<u64, String> + Send + Sync>>: Freeze,
PhantomData<Ev<E>>: Freeze,
PhantomData<Arc<dyn Fn(&ExprArgs<'_, C, E>) -> Value + Send + Sync>>: Freeze,
PhantomData<Arc<dyn Fn(&ContextArgs<'_>) -> Value + Send + Sync>>: Freeze,
PhantomData<Dynamic<Arc<dyn Fn() -> Result<(), String> + Send + Sync>>>: Freeze,
PhantomData<Dynamic<Box<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>>>: Freeze,
PhantomData<fn() -> DefaultHasher>: Freeze,
PhantomData<(String, Arc<dyn Fn(&Value) -> Result<Arc<dyn Fn() -> Result<(), String> + Send + Sync>, String> + Send + Sync>)>: Freeze,
PhantomData<String>: Freeze,
PhantomData<(String, u32)>: Freeze,
C: Freeze,
PhantomData<Value>: Freeze,
PhantomData<usize>: Freeze,
PhantomData<Bucket<String, Value>>: Freeze,
PhantomData<(String, Template)>: Freeze,
PhantomData<Template>: Freeze,
*const ArcInner<Vec<(u32, Vec<u32>)>> is !null: Freeze,
PhantomData<ArcInner<Vec<(u32, Vec<u32>)>>>: Freeze,
*const ArcInner<IndexMap<String, ActorRef, BuildHasherDefault<DefaultHasher>>> is !null: Freeze,
PhantomData<ArcInner<IndexMap<String, ActorRef, BuildHasherDefault<DefaultHasher>>>>: Freeze,
*const ArcInner<Vec<LogicalTimer<E>>> is !null: Freeze,
PhantomData<ArcInner<Vec<LogicalTimer<E>>>>: Freeze,
impl<C, E> Move for Machine<C, E>
impl<C, E> Send for Machine<C, E>where
E: Send,
C: Send,
RawVecInner: Send,
RawTable<usize>: Send,
Arc<dyn Logic>: Send,
Arc<[u32]>: Send,
BoxRaw<Guard>: Send,
BoxRaw<Template>: Send,
BoxRaw<Value>: Send,
BoxRaw<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>: Send,
Arc<dyn Fn() -> Result<(), String> + Send + Sync>: Send,
BoxRaw<dyn Fn(&C, &Ev<E>) -> Result<u64, String> + Send + Sync>: Send,
&'static str: Send,
String: Send,
Arc<dyn Fn(&ExprArgs<'_, C, E>) -> Value + Send + Sync>: Send,
Arc<dyn Fn(&ContextArgs<'_>) -> Value + Send + Sync>: Send,
Arc<dyn Fn(&Value) -> Result<Arc<dyn Fn() -> Result<(), String> + Send + Sync>, String> + Send + Sync>: Send,
Arc<dyn Fn(&Value) -> Result<Box<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>, String> + Send + Sync>: Send,
RawTable<(String, Arc<dyn Fn(&Value) -> Result<Arc<dyn Fn() -> Result<(), String> + Send + Sync>, String> + Send + Sync>)>: Send,
RawTable<(String, u32)>: Send,
Arc<Vec<(u32, Vec<u32>)>>: Send,
Arc<IndexMap<String, ActorRef, BuildHasherDefault<DefaultHasher>>>: Send,
Arc<Vec<LogicalTimer<E>>>: Send,
impl<C, E> Sync for Machine<C, E>where
E: Sync,
C: Sync,
RawVecInner: Sync,
RawTable<usize>: Sync,
Arc<dyn Logic>: Sync,
Arc<[u32]>: Sync,
BoxRaw<Guard>: Sync,
BoxRaw<Template>: Sync,
BoxRaw<Value>: Sync,
BoxRaw<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>: Sync,
Arc<dyn Fn() -> Result<(), String> + Send + Sync>: Sync,
BoxRaw<dyn Fn(&C, &Ev<E>) -> Result<u64, String> + Send + Sync>: Sync,
String: Sync,
Arc<dyn Fn(&ExprArgs<'_, C, E>) -> Value + Send + Sync>: Sync,
Arc<dyn Fn(&ContextArgs<'_>) -> Value + Send + Sync>: Sync,
Arc<dyn Fn(&Value) -> Result<Arc<dyn Fn() -> Result<(), String> + Send + Sync>, String> + Send + Sync>: Sync,
Arc<dyn Fn(&Value) -> Result<Box<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>, String> + Send + Sync>: Sync,
RawTable<(String, Arc<dyn Fn(&Value) -> Result<Arc<dyn Fn() -> Result<(), String> + Send + Sync>, String> + Send + Sync>)>: Sync,
RawTable<(String, u32)>: Sync,
Arc<Vec<(u32, Vec<u32>)>>: Sync,
Arc<IndexMap<String, ActorRef, BuildHasherDefault<DefaultHasher>>>: Sync,
Arc<Vec<LogicalTimer<E>>>: Sync,
impl<C, E> Unpin for Machine<C, E>where
E: Unpin,
C: Unpin,
*const u8 is !null: Unpin,
Arc<dyn Logic>: Unpin,
Arc<[u32]>: Unpin,
Box<Guard>: Unpin,
Box<Template>: Unpin,
Box<Value>: Unpin,
Box<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>: Unpin,
Arc<dyn Fn() -> Result<(), String> + Send + Sync>: Unpin,
Box<dyn Fn(&C, &Ev<E>) -> Result<u64, String> + Send + Sync>: Unpin,
&'static str: Unpin,
String: Unpin,
Arc<dyn Fn(&ExprArgs<'_, C, E>) -> Value + Send + Sync>: Unpin,
Arc<dyn Fn(&ContextArgs<'_>) -> Value + Send + Sync>: Unpin,
Arc<dyn Fn(&Value) -> Result<Arc<dyn Fn() -> Result<(), String> + Send + Sync>, String> + Send + Sync>: Unpin,
Arc<dyn Fn(&Value) -> Result<Box<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>, String> + Send + Sync>: Unpin,
Arc<Vec<(u32, Vec<u32>)>>: Unpin,
Arc<IndexMap<String, ActorRef, BuildHasherDefault<DefaultHasher>>>: Unpin,
Arc<Vec<LogicalTimer<E>>>: Unpin,
impl<C, E> UnsafeUnpin for Machine<C, E>where
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<TreeNode>: UnsafeUnpin,
PhantomData<TreeTransition>: UnsafeUnpin,
PhantomData<NodeData>: UnsafeUnpin,
PhantomData<TransitionData>: UnsafeUnpin,
PhantomData<Box<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>>: UnsafeUnpin,
PhantomData<CustomAction>: UnsafeUnpin,
PhantomData<(String, Arc<dyn Logic>)>: UnsafeUnpin,
PhantomData<Box<dyn Fn(&C, &Ev<E>) -> Result<u64, String> + Send + Sync>>: UnsafeUnpin,
PhantomData<Ev<E>>: UnsafeUnpin,
PhantomData<Arc<dyn Fn(&ExprArgs<'_, C, E>) -> Value + Send + Sync>>: UnsafeUnpin,
PhantomData<Arc<dyn Fn(&ContextArgs<'_>) -> Value + Send + Sync>>: UnsafeUnpin,
PhantomData<Dynamic<Arc<dyn Fn() -> Result<(), String> + Send + Sync>>>: UnsafeUnpin,
PhantomData<Dynamic<Box<dyn Fn(&GuardArgs<'_, C, E>) -> Result<bool, String> + Send + Sync>>>: UnsafeUnpin,
PhantomData<fn() -> DefaultHasher>: UnsafeUnpin,
PhantomData<(String, Arc<dyn Fn(&Value) -> Result<Arc<dyn Fn() -> Result<(), String> + Send + Sync>, String> + Send + Sync>)>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<(String, u32)>: UnsafeUnpin,
C: UnsafeUnpin,
PhantomData<Value>: UnsafeUnpin,
PhantomData<usize>: UnsafeUnpin,
PhantomData<Bucket<String, Value>>: UnsafeUnpin,
PhantomData<(String, Template)>: UnsafeUnpin,
PhantomData<Template>: UnsafeUnpin,
*const ArcInner<Vec<(u32, Vec<u32>)>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Vec<(u32, Vec<u32>)>>>: UnsafeUnpin,
*const ArcInner<IndexMap<String, ActorRef, BuildHasherDefault<DefaultHasher>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<IndexMap<String, ActorRef, BuildHasherDefault<DefaultHasher>>>>: UnsafeUnpin,
*const ArcInner<Vec<LogicalTimer<E>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Vec<LogicalTimer<E>>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more