Struct stakker::Ret

source ·
pub struct Ret<M: 'static>(_);
Expand description

Returner for messages of type M

Typically this would be created using one of the ret_*! macros. 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§

source§

impl<M> Ret<M>

source

pub fn ret(self, msg: M)

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.

source

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

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.

source

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

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

source

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

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.

source

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

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

source

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

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.

source

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

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

Trait Implementations§

source§

impl<M> Drop for Ret<M>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.