pub trait StateMachine: Model {
type State: Copy + PartialEq + Display + Send + Sync + 'static;
const COLUMN: Col<Self, Self::State>;
// Required method
fn machine() -> Machine<Self>;
// Provided methods
fn available<'a>(
&'a self,
user: &'a AuthUser,
db: &'a Db,
) -> impl Future<Output = Result<Vec<Available>>> + Send + 'a
where Self: Sized { ... }
fn insert_in_state<'a>(
&'a mut self,
tx: &'a mut Transaction,
state: Self::State,
reason: &'a str,
) -> impl Future<Output = Result> + Send + 'a
where Self: Sized { ... }
fn transition(&self, name: &str) -> TransitionBuilder<'_, Self>
where Self: Sized { ... }
}Expand description
A model whose status column moves through a Machine.
State is usually a #[derive(DbEnum)] enum: its text (Display) is the
name of a state in the machine, in the history and in diagrams.
Required Associated Constants§
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn available<'a>(
&'a self,
user: &'a AuthUser,
db: &'a Db,
) -> impl Future<Output = Result<Vec<Available>>> + Send + 'awhere
Self: Sized,
fn available<'a>(
&'a self,
user: &'a AuthUser,
db: &'a Db,
) -> impl Future<Output = Result<Vec<Available>>> + Send + 'awhere
Self: Sized,
The transitions user may run on this record now, for buttons and
menus: the user’s permission (in the record’s scope for
permission_in), the record’s state and the guards all hold. System
transitions are left out. Nothing is written: the guards run (so they
must be side-effect free) and the interceptor is only asked to
preview, which sets requires_approval.
Sourcefn insert_in_state<'a>(
&'a mut self,
tx: &'a mut Transaction,
state: Self::State,
reason: &'a str,
) -> impl Future<Output = Result> + Send + 'awhere
Self: Sized,
fn insert_in_state<'a>(
&'a mut self,
tx: &'a mut Transaction,
state: Self::State,
reason: &'a str,
) -> impl Future<Output = Result> + Send + 'awhere
Self: Sized,
Inserts this record in state even though the machine’s initial
states don’t include it (an import, a fixture, a record born
mid-way), and writes a history row with no from state and reason.
Runs in tx and doesn’t commit.
The record’s status must already be state (set the field first):
the argument is the explicit statement of the exception. A plain
insert/save of a record in a non-initial state is refused when the
machine declares initial.
Sourcefn transition(&self, name: &str) -> TransitionBuilder<'_, Self>where
Self: Sized,
fn transition(&self, name: &str) -> TransitionBuilder<'_, Self>where
Self: Sized,
Starts running the transition called name on this record; chain
by (or by_system), optionally reason, input and meta, and end
with run or run_in.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".