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>
impl<M> Ret<M>
sourcepub fn new(f: impl FnOnce(Option<M>) + 'static) -> Self
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.
sourcepub fn to_actor<A: 'static>(
actor: Actor<A>,
f: impl FnOnce(&mut A, &mut Cx<'_, A>, Option<M>) + 'static
) -> Self
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.
sourcepub fn to_actor_prep<A: 'static>(
actor: Actor<A>,
f: impl FnOnce(&mut Cx<'_, A>, Option<M>) -> Option<A> + 'static
) -> Self
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.