Skip to main content

UpdateResult

Struct UpdateResult 

Source
pub struct UpdateResult<S, M> {
    pub state: Option<S>,
    pub command: Command<M>,
}
Expand description

Result of an update operation.

This provides a convenient way to return both state changes and commands from an update function.

Fields§

§state: Option<S>

The updated state (if changed)

§command: Command<M>

Commands to execute

Implementations§

Source§

impl<S, M> UpdateResult<S, M>

Source

pub fn none() -> Self

Creates a result with no state change and no command.

Source

pub fn state(state: S) -> Self

Creates a result with updated state.

Source

pub fn command(command: Command<M>) -> Self

Creates a result with a command.

Source

pub fn with(state: S, command: Command<M>) -> Self

Creates a result with both state and command.

Source

pub fn and_command(self, command: Command<M>) -> Self

Adds a command to this result.

Source

pub fn map_state<T, F>(self, f: F) -> UpdateResult<T, M>
where F: FnOnce(S) -> T,

Maps the state type.

Source

pub fn map_message<N, F>(self, f: F) -> UpdateResult<S, N>
where F: Fn(M) -> N + Clone + Send + 'static, M: Send + 'static, N: Send + 'static,

Maps the message type.

Trait Implementations§

Source§

impl<S: Debug, M: Debug> Debug for UpdateResult<S, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, M> Default for UpdateResult<S, M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S, M> Freeze for UpdateResult<S, M>
where S: Freeze,

§

impl<S, M> !RefUnwindSafe for UpdateResult<S, M>

§

impl<S, M> Send for UpdateResult<S, M>
where S: Send, M: Send,

§

impl<S, M> !Sync for UpdateResult<S, M>

§

impl<S, M> Unpin for UpdateResult<S, M>
where S: Unpin, M: Unpin,

§

impl<S, M> UnsafeUnpin for UpdateResult<S, M>
where S: UnsafeUnpin,

§

impl<S, M> !UnwindSafe for UpdateResult<S, M>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> StateExt for T

Source§

fn updated(self, cmd: Command<impl Clone>) -> UpdateResult<Self, impl Clone>

Updates self and returns a command.
Source§

fn unchanged(self) -> UpdateResult<Self, ()>

Returns self with no command.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.