Skip to main content

System

Struct System 

Source
pub struct System { /* private fields */ }
Expand description

A running actor system.

Implementations§

Source§

impl System

Source

pub fn initialize( logic: &SystemLogic, options: InitOptions, ) -> Result<(Self, Vec<ExternalEffect>), SystemError>

XState’s initialSystemTransition: allocates and starts the root. Returns the system and the external effects produced.

Source

pub fn root(&self) -> &str

The root actor’s address.

Source

pub fn root_address(&self) -> &Arc<str> ⓘ

System::root, shared.

Source

pub fn now(&self) -> u64

Virtual time.

Source

pub fn next_deadline(&self) -> Option<u64>

The earliest pending deadline.

Source

pub fn try_clone(&self) -> Option<Self>

A copy of the system, with its own snapshots, and the logic and effects’ implementations shared: what crate::Actor::apply keeps to undo a chunk. None when an actor’s snapshot cannot be copied (AnySnapshot::clone_box), as one of logic outside this crate.

Source

pub fn external_effects(&self) -> impl Iterator<Item = &ExternalEffect>

Pending external work, by id.

Source

pub fn actor_ref(&self, address: &str) -> Option<ActorRef>

The current reference of the actor at address.

Source

pub fn registry(&self) -> impl Iterator<Item = (&str, &ActorRef)>

The registry: key to actor.

Source

pub fn logic(&self) -> &SystemLogic

The logic the system was created with.

Source

pub fn actor_src(&self, address: &str) -> Option<&str>

The src of the actor at address: the path of its logic, as root/actors/fetchUser, or root for the root.

Source

pub fn actor_logic( &self, address: &str, ) -> Option<(Option<String>, Option<&Value>)>

The logic id (Logic::logic_id: for async logic, the name it was registered under) and the input of the actor at address.

Source

pub fn snapshot(&self, address: &str) -> Option<&dyn AnySnapshot>

The snapshot of the actor at address.

Source

pub fn check( &self, address: &str, event: &Value, ) -> Result<TransitionCheck, SystemError>

What the actor at address would do with event, as XState’s snapshot.check(event) (Logic::check), at the system’s current time (no due timer fires). Nothing changes: the event is not sent, no action runs and no actor is created.

Source

pub fn handles(&self, address: &str, event: &Value) -> Result<bool, SystemError>

Whether the actor at address selects a transition of event (see Logic::handles): false of an actor with no snapshot.

Source

pub fn max_steps(&self) -> usize

The bound of messages, timers and allocations per call.

Source

pub fn fire_next_timer( &mut self, time: u64, ) -> Result<Option<Vec<ExternalEffect>>, SystemError>

Fires only the earliest timer occurrence due at or before time (the clock moves to its due time), as a live actor processes each timer as its own step. Returns None when no timer is due.

Source

pub fn advance(&mut self, time: u64) -> Result<Vec<ExternalEffect>, SystemError>

XState’s advanceSystemTime: fires every timer due at or before time, chronologically, then sets the clock to time.

Source

pub fn send( &mut self, address: &str, event: Value, ) -> Result<Vec<ExternalEffect>, SystemError>

XState’s systemTransition: delivers event to the actor at address and completes all resulting work. Due timers fire first.

Source

pub fn resolve_effect( &mut self, effect_id: &str, event: Option<Value>, ) -> Result<Vec<ExternalEffect>, SystemError>

Acknowledges external work, optionally delivering its result to the actor that requested it (xstate.system.effect.result).

Source

pub fn acknowledge(&mut self, effect_id: &str) -> bool

Retires pending external work without delivering a result (an xstate.system.effect.result without event). Returns whether it was pending.

Source

pub fn to_json(&self) -> Value

XState’s SystemSnapshot as JSON.

Source

pub fn from_json( logic: &SystemLogic, data: &Value, max_steps: usize, ) -> Result<Self, SystemError>

Restores a system from System::to_json data and the same logic.

Source§

impl System

Source

pub fn view(&self) -> SystemView<'_>

The system snapshot as a SystemView: serializes to the same data as System::to_json, without building it.

Source

pub fn compact_view(&self) -> SystemView<'_>

A smaller snapshot that System::from_json restores to the same system: XState’s SystemSnapshot without the fields restore rebuilds identically when they are missing (empty collections, the default execution id, actor addresses, which are the keys of actors, and in machine snapshots the state value, derived from nodeIds, and empty children, historyValue, timers and stateInputs). It is not meant for XState’s own restore.

Auto Trait Implementations§

§

impl !RefUnwindSafe for System

§

impl !Sync for System

§

impl !UnwindSafe for System

§

impl Forget for System

§

impl Freeze for System
where *const ArcInner<dyn Logic> is !null: Freeze, PhantomData<ArcInner<dyn Logic>>: Freeze, *const u8 is !null: Freeze, PhantomData<(String, Arc<dyn Logic>)>: Freeze, *const ArcInner<Vec<(String, Arc<dyn Logic>)>> is !null: Freeze, PhantomData<ArcInner<Vec<(String, Arc<dyn Logic>)>>>: Freeze, &'static str: Freeze, String: Freeze, *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze, PhantomData<ActorEntry>: Freeze, PhantomData<usize>: Freeze, PhantomData<Bucket<String, ActorRef>>: Freeze, PhantomData<fn() -> DefaultHasher>: Freeze, PhantomData<Message>: Freeze, PhantomData<Bucket<String, SystemTimer>>: Freeze, PhantomData<Reverse<(u64, u64, u64)>>: Freeze, PhantomData<Bucket<String, ExternalEffect>>: Freeze, *const SystemError is !null: Freeze, PhantomData<SystemError>: Freeze, *const Scratch is !null: Freeze, PhantomData<Scratch>: Freeze,

§

impl Move for System

§

impl Send for System
where Arc<dyn Logic>: Send, RawVecInner: Send, Arc<Vec<(String, Arc<dyn Logic>)>>: Send, &'static str: Send, String: Send, Arc<str>: Send, BoxRaw<str>: Send, BoxRaw<Value>: Send, BoxRaw<dyn AnySnapshot>: Send, RawTable<usize>: Send, Arc<dyn Fn() -> Result<(), String> + Send + Sync>: Send, BoxRaw<SystemError>: Send, BoxRaw<Scratch>: Send,

§

impl Unpin for System
where Arc<dyn Logic>: Unpin, *const u8 is !null: Unpin, Arc<Vec<(String, Arc<dyn Logic>)>>: Unpin, &'static str: Unpin, String: Unpin, Arc<str>: Unpin, Box<str>: Unpin, Box<Value>: Unpin, Box<dyn AnySnapshot>: Unpin, Arc<dyn Fn() -> Result<(), String> + Send + Sync>: Unpin, Box<SystemError>: Unpin, Box<Scratch>: Unpin,

§

impl UnsafeUnpin for System

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.