[][src]Struct stakker::Ret

pub struct Ret<M: 'static>(_);

Returner for messages of type M

This can be called only once, and if dropped, it will return a message of None.

This is a fat pointer to a boxed dynamic FnOnce, so it consumes two usize locally, and the size of the FnOnce closure on the heap. It is a "move" type, so does not support Copy or Clone. It must be passed around by moving, and pulled out of composite types by destructuring (if the compiler doesn't automatically destructure for you). The Ret::ret call takes self which gives a compile-time guarantee that it is used only once.

For zero arguments, use Ret<()>. For one argument, use Ret<type>, where type is the type of the argument. For two or more use a tuple: Ret<(type1, type2...)>. Call the Ret::ret method to send a message or use the ret! macro. Sending a message typically results in the asynchronous execution of an actor call, but may have other effects depending on the type of returner.

Implementations

impl<M> Ret<M>[src]

pub fn ret(self, msg: M)[src]

Return a message through the Ret instance. This uses self which guarantees that it will be called only once. So this will not work on a reference to the Ret instance. The tuple or struct containing the Ret instance needs to be destructured to move the Ret instance out first.

pub fn new(f: impl FnOnce(Option<M>) + 'static) -> Self[src]

Create a Ret instance that performs an arbitrary action with the message on being called. The call is made synchronously at the point that the message is forwarded. None is passed if the instance is dropped.

pub fn to_actor<A: 'static>(
    actor: Actor<A>,
    f: impl FnOnce(&mut A, &mut Cx<'_, A>, Option<M>) + 'static
) -> Self
[src]

Create a Ret instance that queues a call to an actor.

pub fn to_actor_prep<A: 'static>(
    actor: Actor<A>,
    f: impl FnOnce(&mut Cx<'_, A>, Option<M>) -> Option<A> + 'static
) -> Self
[src]

Create a Ret instance that queues calls to an actor whilst in the Prep phase. Once the actor is Ready, any queued prep calls are dropped.

pub fn some_to_actor<A: 'static>(
    actor: Actor<A>,
    f: impl FnOnce(&mut A, &mut Cx<'_, A>, M) + 'static
) -> Self
[src]

Create a Ret instance that queues a call to an actor if a value is returned, but not if the Ret instance is dropped.

pub fn some_to_actor_prep<A: 'static>(
    actor: Actor<A>,
    f: impl FnOnce(&mut Cx<'_, A>, M) -> Option<A> + 'static
) -> Self
[src]

Create a Ret instance that queues calls for returned values (but not if the Ret instance is dropped) to an actor whilst in the Prep phase. Once the actor is Ready, any queued prep calls are dropped.

pub fn panic(msg: impl Into<String>) -> Self[src]

Create a Ret instance that panics with the given message when called

Trait Implementations

impl<M> Drop for Ret<M>[src]

Auto Trait Implementations

impl<M> !RefUnwindSafe for Ret<M>

impl<M> !Send for Ret<M>

impl<M> !Sync for Ret<M>

impl<M> Unpin for Ret<M>

impl<M> !UnwindSafe for Ret<M>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.