Crate state_unit
source ·Expand description
VM state machine unit handling.
A state unit is a VM component (such as a device) that needs to react to changes in the VM state machine. It needs to start, stop, reset, and save/restore with the VM. (Save/restore is not really a state change but is modeled as such since it must be synchronized with actual state changes.)
This module contains types and functions for defining and manipulating state units. It does this in three parts:
-
It defines an RPC enum
StateRequest
which is used to request that a state unit change state (start, stop, etc.). Each state unit must handle incoming state requests on a mesh receiver. This is the foundational type of this model. -
It defines a type
StateUnits
, which is a collection of mesh senders for sendingStateRequest
s. This is used to initiate and wait for state changes across all the units in the VMM, handling any required dependency ordering. -
It defines a trait
StateUnit
that can be used to define handlers for each state request. This is an optional convenience; not all state units will have a type that implements this trait.
This model allows for asynchronous, highly concurrent state changes, and it
works across process boundaries thanks to mesh
.
Structs§
- An error returned when a state unit name is already in use.
- The saved state for an individual unit.
- A handle to a spawned unit.
- An error from a state transition.
- A set of state units.
- An object returned by
StateUnits::inspector
to inspect state units while state transitions may be in flight. - A builder returned by
StateUnits::add
. - A handle returned by
StateUnits::add
, used to remove the state unit.
Enums§
- A state change request.
Traits§
- Trait implemented by an object that can act as a state unit.
Functions§
- Runs a state unit that can handle inspect requests while there is an active state transition.
- Runs a simple unit that only needs to respond to state requests.