pub struct Transition<M: StateMachine> { /* private fields */ }Expand description
A change between states, built with Transition::new.
Implementations§
Source§impl<M: StateMachine> Transition<M>
impl<M: StateMachine> Transition<M>
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
A transition called name (e.g. place), open to any logged-in user
until you restrict it with permission, permission_in or system.
Sourcepub fn from<S: Display>(self, states: impl IntoIterator<Item = S>) -> Self
pub fn from<S: Display>(self, states: impl IntoIterator<Item = S>) -> Self
The states it may start from.
Sourcepub fn label(self, label: impl Into<String>) -> Self
pub fn label(self, label: impl Into<String>) -> Self
The button text (default: the name with spaces, capitalised: Mark paid).
Sourcepub fn reason_required(self) -> Self
pub fn reason_required(self) -> Self
The run must give a reason (the button asks for one).
Sourcepub fn permission(self, permission: impl Into<String>) -> Self
pub fn permission(self, permission: impl Into<String>) -> Self
Only users holding permission (the Permissions module).
Sourcepub fn permission_in(
self,
permission: impl Into<String>,
scope: impl Fn(&M) -> Scope + Send + Sync + 'static,
) -> Self
pub fn permission_in( self, permission: impl Into<String>, scope: impl Fn(&M) -> Scope + Send + Sync + 'static, ) -> Self
Only users holding permission in the scope scope gives for the
record (e.g. its store), or globally.
Sourcepub fn guard<F>(self, name: impl Into<String>, guard: F) -> Self
pub fn guard<F>(self, name: impl Into<String>, guard: F) -> Self
A condition that must hold: the closure returns Ok(()) or
Err(message). Guards run in the order added, also when asking which
actions are available, so they must not write anything. Name the
record’s type on the closure’s first parameter
(|order: &Order, ctx| Box::pin(async move { .. })), as the compiler
can’t tell it from the chain.
Sourcepub fn effect<F>(self, effect: F) -> Selfwhere
F: for<'a> Fn(&'a M, &'a TransitionCtx, &'a mut Transaction) -> BoxFuture<'a, Result> + Send + Sync + 'static,
pub fn effect<F>(self, effect: F) -> Selfwhere
F: for<'a> Fn(&'a M, &'a TransitionCtx, &'a mut Transaction) -> BoxFuture<'a, Result> + Send + Sync + 'static,
Work that runs with the transition, in its transaction: if it fails, the status change and the history row are rolled back. Effects run in the order added.
Sourcepub fn label_text(&self) -> String
pub fn label_text(&self) -> String
The button text.
Sourcepub fn from_states(&self) -> &[String]
pub fn from_states(&self) -> &[String]
The states it may start from.
Sourcepub fn needs_reason(&self) -> bool
pub fn needs_reason(&self) -> bool
Whether a reason must be given.
Sourcepub fn guard_names(&self) -> Vec<&str>
pub fn guard_names(&self) -> Vec<&str>
The names of its guards, in order.
Sourcepub fn check_access(
&self,
record: &M,
actor: Option<&AuthUser>,
) -> Result<(), TransitionError>
pub fn check_access( &self, record: &M, actor: Option<&AuthUser>, ) -> Result<(), TransitionError>
Checks who is running it: authentication, then permission (in the
record’s scope for permission_in). actor is None for a system
run, which only system transitions accept; a user may not run one.
Sourcepub fn check_from(&self, current: impl Display) -> Result<(), TransitionError>
pub fn check_from(&self, current: impl Display) -> Result<(), TransitionError>
Checks the record’s current state is one the transition leaves.
Sourcepub async fn check_guards(
&self,
record: &M,
ctx: &TransitionCtx,
) -> Result<(), TransitionError>
pub async fn check_guards( &self, record: &M, ctx: &TransitionCtx, ) -> Result<(), TransitionError>
Runs the guards in order and stops at the first that says no.
Sourcepub async fn run_effects(
&self,
record: &M,
ctx: &TransitionCtx,
tx: &mut Transaction,
) -> Result
pub async fn run_effects( &self, record: &M, ctx: &TransitionCtx, tx: &mut Transaction, ) -> Result
Runs the effects in order inside tx, stopping at the first failure.
Auto Trait Implementations§
impl<M> !RefUnwindSafe for Transition<M>
impl<M> !UnwindSafe for Transition<M>
impl<M> Freeze for Transition<M>where
Access<M>: Freeze,
Vec<(String, Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> + Send + Sync>)>: Freeze,
Vec<Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx, &'a mut Transaction) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> + Send + Sync>>: Freeze,
impl<M> Send for Transition<M>where
Access<M>: Send,
Vec<(String, Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> + Send + Sync>)>: Send,
Vec<Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx, &'a mut Transaction) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> + Send + Sync>>: Send,
impl<M> Sync for Transition<M>where
Access<M>: Sync,
Vec<(String, Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> + Send + Sync>)>: Sync,
Vec<Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx, &'a mut Transaction) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> + Send + Sync>>: Sync,
impl<M> Unpin for Transition<M>where
Access<M>: Unpin,
Vec<(String, Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> + Send + Sync>)>: Unpin,
Vec<Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx, &'a mut Transaction) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> + Send + Sync>>: Unpin,
impl<M> UnsafeUnpin for Transition<M>where
Access<M>: UnsafeUnpin,
Vec<(String, Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> + Send + Sync>)>: UnsafeUnpin,
Vec<Arc<dyn for<'a> Fn(&'a M, &'a TransitionCtx, &'a mut Transaction) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> + Send + Sync>>: 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more