Skip to main content

Transition

Struct Transition 

Source
pub struct Transition<M: StateMachine> { /* private fields */ }
Expand description

A change between states, built with Transition::new.

Implementations§

Source§

impl<M: StateMachine> Transition<M>

Source

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.

Source

pub fn from<S: Display>(self, states: impl IntoIterator<Item = S>) -> Self

The states it may start from.

Source

pub fn to(self, state: impl Display) -> Self

The state it ends in.

Source

pub fn label(self, label: impl Into<String>) -> Self

The button text (default: the name with spaces, capitalised: Mark paid).

Source

pub fn tone(self, tone: impl Into<String>) -> Self

A tone for its button (primary, danger, …).

Source

pub fn reason_required(self) -> Self

The run must give a reason (the button asks for one).

Source

pub fn permission(self, permission: impl Into<String>) -> Self

Only users holding permission (the Permissions module).

Source

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.

Source

pub fn system(self) -> Self

Only the system may run it (by_system), e.g. a scheduled task.

Source

pub fn guard<F>(self, name: impl Into<String>, guard: F) -> Self
where F: for<'a> Fn(&'a M, &'a TransitionCtx) -> BoxFuture<'a, Result<(), String>> + Send + Sync + 'static,

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.

Source

pub fn effect<F>(self, effect: F) -> Self
where 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.

Source

pub fn name(&self) -> &str

The transition’s name.

Source

pub fn label_text(&self) -> String

The button text.

Source

pub fn tone_name(&self) -> Option<&str>

The button’s tone, if set.

Source

pub fn from_states(&self) -> &[String]

The states it may start from.

Source

pub fn to_state(&self) -> Option<&str>

The state it ends in.

Source

pub fn needs_reason(&self) -> bool

Whether a reason must be given.

Source

pub fn is_system(&self) -> bool

Whether only the system may run it.

Source

pub fn guard_names(&self) -> Vec<&str>

The names of its guards, in order.

Source

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.

Source

pub fn check_from(&self, current: impl Display) -> Result<(), TransitionError>

Checks the record’s current state is one the transition leaves.

Source

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.

Source

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more