Struct actix::Recipient

source ·
pub struct Recipient<M>
where M: Message + Send, M::Result: Send,
{ /* private fields */ }
Expand description

The Recipient type allows to send one specific message to an actor.

You can get a recipient using the Addr::recipient() method. It is possible to use the Clone::clone() method to get a cloned recipient.

Implementations§

source§

impl<M> Recipient<M>
where M: Message + Send, M::Result: Send,

source

pub fn do_send(&self, msg: M)

Sends a message.

The message is always queued, even if the mailbox for the receiver is full. If the mailbox is closed, the message is silently dropped.

Examples found in repository?
examples/weak_recipient.rs (line 29)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    fn send_tick(&mut self, _ctx: &mut Context<Self>) {
        for client in self.clients.iter() {
            if let Some(client) = client.upgrade() {
                client.do_send(TimePing(Instant::now()));
                println!("⏰ sent ping to client {:?}", client);
            } else {
                println!("⏰ client can no longer be upgraded");
            }
        }

        // gc
        self.clients = self
            .clients
            .drain(..)
            .filter(|c| c.upgrade().is_some())
            .collect();
        println!("⏰ service has {} clients", self.clients.len());
    }
More examples
Hide additional examples
examples/ring.rs (line 54)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    fn handle(&mut self, msg: Payload, _: &mut Context<Self>) {
        if msg.0 >= self.limit {
            println!(
                "Actor {} reached limit of {} (payload was {})",
                self.id, self.limit, msg.0
            );

            System::current().stop();
            return;
        }

        // Some prime in order for different actors to report progress.
        // Large enough to print about once per second in debug mode.
        if msg.0 % 498989 == 1 {
            println!(
                "Actor {} received message {} of {} ({:.2}%)",
                self.id,
                msg.0,
                self.limit,
                100.0 * msg.0 as f32 / self.limit as f32
            );
        }

        self.next.do_send(Payload(msg.0 + 1));
    }
source

pub fn try_send(&self, msg: M) -> Result<(), SendError<M>>

Attempts to send a message.

This method fails if the actor’s mailbox is full or closed. This method registers the current task in the receivers queue.

source

pub fn send(&self, msg: M) -> RecipientRequest<M>

Sends a message and asynchronously wait for a response.

The communication channel to the actor is bounded. If the returned RecipientRequest object gets dropped, the message is cancelled.

source

pub fn connected(&self) -> bool

source

pub fn downgrade(&self) -> WeakRecipient<M>

Returns a downgraded WeakRecipient

Trait Implementations§

source§

impl<M> Clone for Recipient<M>
where M: Message + Send, M::Result: Send,

source§

fn clone(&self) -> Recipient<M>

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
source§

impl<M> Debug for Recipient<M>
where M: Message + Send, M::Result: Send,

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<A, M: Message + Send + 'static> From<Addr<A>> for Recipient<M>
where A: Handler<M> + Actor, M::Result: Send, A::Context: ToEnvelope<A, M>,

source§

fn from(addr: Addr<A>) -> Self

Converts to this type from the input type.
source§

impl<M> From<Recipient<M>> for WeakRecipient<M>
where M: Message + Send, M::Result: Send,

source§

fn from(recipient: Recipient<M>) -> Self

Converts to this type from the input type.
source§

impl<M> Hash for Recipient<M>
where M: Message + Send, M::Result: Send,

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<M> PartialEq for Recipient<M>
where M: Message + Send, M::Result: Send,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<M> Eq for Recipient<M>
where M: Message + Send, M::Result: Send,

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for Recipient<M>

§

impl<M> Send for Recipient<M>

§

impl<M> Sync for Recipient<M>

§

impl<M> Unpin for Recipient<M>

§

impl<M> !UnwindSafe for Recipient<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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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,

§

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

§

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

§

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more