Struct Response

Source
pub struct Response<M, N>(/* private fields */);
Expand description

The response of a state machine to the (mio) action

This value is returned by many methods of the Machine trait.

Implementations§

Source§

impl<M: Sized, N: Sized> Response<M, N>

Source

pub fn ok(machine: M) -> Response<M, N>

Source

pub fn spawn(machine: M, result: N) -> Response<M, N>

Source

pub fn done() -> Response<M, N>

Source

pub fn error(e: Box<dyn Error>) -> Response<M, N>

Source

pub fn deadline(self, time: Time) -> Response<M, N>

Source

pub fn map<T, U, S, R>(self, self_mapper: S, result_mapper: R) -> Response<T, U>
where S: FnOnce(M) -> T, R: FnOnce(N) -> U,

Maps state machine and/or spawned result with a function

Usually it’s okay to use constructor of wrapper state machine here as a mapper

Source

pub fn wrap<T, S>(self, self_mapper: S) -> Response<T, N>
where S: FnOnce(M) -> T,

Similar to map but only maps state machine

This is especially useful in state machine constructors, which have a Void child type.

Source

pub fn is_stopped(&self) -> bool

Returns true if state machine is stopped

I.e. the method returns true if the Response was created either with Response::done or Response::error

Source

pub fn cause(&self) -> Option<&dyn Error>

Return a reference to an error passed to Response::error

Returns None if any other constructor was used.

This is mostly useful for printing the error.

Source§

impl<M: Sized + Debug, N: Sized + Debug> Response<M, N>

Source

pub fn expect_machine(self) -> M

Return state machine if response created with Response::ok(..)

Use only for unit tests

If the response is not okay, the function panics.

Source

pub fn expect_spawn(self) -> (M, N)

Return a tuple if response created with Response::spawn(..)

Use only for unit tests

If the response is not spawn, the function panics.

Source

pub fn expect_done(self)

Returns if response created with Response::done()

Use only for unit tests

If the response is not done, the function panics.

Source

pub fn expect_error(self) -> Box<dyn Error>

Returns an error if response created with Response::error(..)

Use only for unit tests

If the response does not contain error, the function panics.

Auto Trait Implementations§

§

impl<M, N> Freeze for Response<M, N>
where M: Freeze, N: Freeze,

§

impl<M, N> !RefUnwindSafe for Response<M, N>

§

impl<M, N> !Send for Response<M, N>

§

impl<M, N> !Sync for Response<M, N>

§

impl<M, N> Unpin for Response<M, N>
where M: Unpin, N: Unpin,

§

impl<M, N> !UnwindSafe for Response<M, N>

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, 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.