pub struct Context<State> {
pub action: ActionContext<State>,
pub state: Option<State>,
}Expand description
The context of the action. This is handed into actions when they’re invoked, and is the underpinning mechanism for distributing side-effects, as well as action composition.
At compile time, the action context grants us, and the consumers, the ability to structure action systems in typesafe ways. At runtime, the context is used to distribute the state of the system, as well as any additional crate-specific plumbing that the action may require.
Fields§
§action: ActionContext<State>The action context, describing any additional context that the action may carry.
state: Option<State>The state of the system, determined by the consumer. This can be absent if the various actions are called before being properly initialized. The type system should prevent this most of the time by requiring the state to be present before invoking actions or calling them as services.
Implementations§
Source§impl<State> Context<State>
impl<State> Context<State>
Sourcepub fn from_action(action: ActionContext<State>) -> Self
pub fn from_action(action: ActionContext<State>) -> Self
Create a new context with the given action.
Sourcepub fn from_state(state: State) -> Self
pub fn from_state(state: State) -> Self
Create a new context with the given state.
Sourcepub fn state(&self) -> Result<State, StateNotReadyError>where
State: Clone,
pub fn state(&self) -> Result<State, StateNotReadyError>where
State: Clone,
Return the state. Returns an error if the state is not ready.
Sourcepub fn with_action(action: ActionContext<State>, state: State) -> Self
pub fn with_action(action: ActionContext<State>, state: State) -> Self
Create a new context with the given state and action context.
Trait Implementations§
Source§impl<State> From<ActionContext<State>> for Context<State>
impl<State> From<ActionContext<State>> for Context<State>
Source§fn from(action: ActionContext<State>) -> Self
fn from(action: ActionContext<State>) -> Self
Auto Trait Implementations§
impl<State> Freeze for Context<State>where
State: Freeze,
impl<State> !RefUnwindSafe for Context<State>
impl<State> Send for Context<State>where
State: Send,
impl<State> Sync for Context<State>where
State: Sync,
impl<State> Unpin for Context<State>where
State: Unpin,
impl<State> !UnwindSafe for Context<State>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)