Struct Fwd

Source
pub struct Fwd<M: 'static>(/* private fields */);
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 duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<M> Freeze for Fwd<M>

§

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 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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