Struct stakker::Fwd

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

Forwarder for messages of type M

Typically this would be created using one of the fwd_*! macros. This may be called many times to forward different messages to the same end-point. For situations where a callback can be used at most one time, prefer Ret, because it is less restrictive on the types of data that may be captured by the closure.

This is a fat pointer to a ref-counted dynamic Fn, so it consumes two usize locally, and the size of the Fn closure plus the ref-count (a usize) on the heap. It may be cloned cheaply if another identical Fwd is required.

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

Implementations§

source§

impl<M> Fwd<M>

source

pub fn fwd(&self, msg: M)

Forward a message through the Fwd instance

source

pub fn new(f: impl Fn(M) + 'static) -> Self

Create a Fwd 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.

source

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

Create a Fwd instance that queues calls to an actor. The Fn provided must be Copy because on each invocation a new copy is made and put on the queue. Use Ret instead if this is too restrictive.

source

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

Create a Fwd 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 panic(msg: impl Into<String>) -> Self

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

Trait Implementations§

source§

impl<M> Clone for Fwd<M>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for Fwd<M>

§

impl<M> !Send for Fwd<M>

§

impl<M> !Sync for Fwd<M>

§

impl<M> Unpin for Fwd<M>

§

impl<M> !UnwindSafe for Fwd<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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.