[][src]Struct xtra_addons::Address

pub struct Address<A, Rc = Strong> where
    Rc: RefCounter,
    A: Actor
{ /* fields omitted */ }

An Address is a reference to an actor through which Messages can be sent. It can be cloned to create more addresses to the same actor. By default (i.e without specifying the second type parameter, Rc, to be weak), Addresses are strong. Therefore, when all Addresses are dropped, the actor will be stopped. In other words, any existing Addresses will inhibit the dropping of an actor. If this is undesirable, then a WeakAddress should be used instead. An address is created by calling the Actor::create or Context::run methods, or by cloning another Address.

Implementations

impl<A> Address<A, Strong> where
    A: Actor
[src]

Functions which apply only to strong addresses (the default kind).

pub fn downgrade(&self) -> Address<A, Weak>[src]

Create a weak address to the actor. Unlike with the strong variety of address (this kind), an actor will not be prevented from being dropped if only weak sinks, channels, and addresses exist.

impl<A> Address<A, Either> where
    A: Actor
[src]

Functions which apply only to addresses which can either be strong or weak.

pub fn downgrade(&self) -> Address<A, Weak>[src]

Converts this address into a weak address.

impl<A, Rc> Address<A, Rc> where
    Rc: RefCounter,
    A: Actor
[src]

Functions which apply to any kind of address, be they strong or weak.

pub fn is_connected(&self) -> bool[src]

Returns whether the actor referred to by this address is running and accepting messages.

struct Shutdown;

impl Message for Shutdown {
    type Result = ();
}

#[async_trait::async_trait]
impl Handler<Shutdown> for MyActor {
    async fn handle(&mut self, _: Shutdown, ctx: &mut Context<Self>) {
        ctx.stop();
    }
}

smol::block_on(async {
    let addr = MyActor.create(None).spawn(&mut Smol::Global);
    assert!(addr.is_connected());
    addr.send(Shutdown).await;
    Timer::after(Duration::from_secs(1)).await; // Give it time to shut down
    assert!(!addr.is_connected());
})

pub fn as_either(&self) -> Address<A, Either>[src]

Convert this address into a generic address which can be weak or strong.

pub fn do_send<M>(&self, message: M) -> Result<(), Disconnected> where
    A: Handler<M>,
    M: Message
[src]

Send a Message to the actor without waiting for a response. If the actor's mailbox is full, it will block. If this returns Err(Disconnected), then the actor is stopped and not accepting messages. If this returns Ok(()), the will be delivered, but may not be handled in the event that the actor stops itself (by calling Context::stop) before it was handled.

pub fn do_send_async<M>(&self, message: M) -> DoSendFuture<A> where
    A: Handler<M>,
    M: Message
[src]

Send a Message to the actor without waiting for a response. If the actor's mailbox is full, it will asynchronously wait. If this returns Err(Disconnected), then the actor is stopped and not accepting messages. If this returns Ok(()), the will be delivered, but may not be handled in the event that the actor stops itself (by calling Context::stop) before it was handled.

pub fn send<M>(&self, message: M) -> SendFuture<A, M> where
    A: Handler<M>,
    M: Message
[src]

Send a Message to the actor and asynchronously wait for a response. If this returns Err(Disconnected), then the actor is stopped and not accepting messages. Like most futures, this must be polled to actually send the message.

pub async fn attach_stream<S, M, K>(self, stream: S) where
    A: Handler<M>,
    M: Message<Result = K>,
    K: Into<KeepRunning> + Send,
    S: Stream<Item = M> + Send
[src]

Attaches a stream to this actor such that all messages produced by it are forwarded to the actor. This could, for instance, be used to forward messages from a socket to the actor (after the messages have been appropriately mapped). This is a convenience method over explicitly forwarding a stream to this address and checking when to stop forwarding.

Often, this should be spawned onto an executor to run in the background. Do not await this inside of an actor - this will cause it to await forever and never receive any messages.

Note: if this stream's continuation should prevent the actor from being dropped, this method should be called on Address. Otherwise, it should be called on WeakAddress.

pub fn into_sink(self) -> AddressSink<A, Rc>[src]

Converts this address into a futures Sink.

Trait Implementations

impl<A, Rc> Clone for Address<A, Rc> where
    Rc: RefCounter,
    A: Actor
[src]

impl<A, Rc> Drop for Address<A, Rc> where
    Rc: RefCounter,
    A: Actor
[src]

impl<A, M, Rc> MessageChannel<M> for Address<A, Rc> where
    Rc: RefCounter,
    A: Handler<M>,
    M: Message
[src]

impl<M> PublishExt<M> for Address<Broker<M>> where
    M: Message<Result = ()> + Clone
[src]

impl<A, M> StrongMessageChannel<M> for Address<A, Strong> where
    A: Handler<M>,
    M: Message
[src]

pub fn upcast(self) -> Box<dyn MessageChannel<M> + 'static, Global>[src]

Upcasts this strong message channel into a boxed generic MessageChannel trait object

pub fn upcast_ref(&self) -> &dyn MessageChannel<M>[src]

Upcasts this strong message channel into a reference to the generic MessageChannel trait object

impl<T, M> SubscribeExt<M> for Address<T> where
    T: Handler<M>,
    M: Message<Result = ()> + Clone
[src]

impl<A, M> WeakMessageChannel<M> for Address<A, Weak> where
    A: Handler<M>,
    M: Message
[src]

pub fn upcast(self) -> Box<dyn MessageChannel<M> + 'static, Global>[src]

Upcasts this weak message channel into a boxed generic MessageChannel trait object

pub fn upcast_ref(&self) -> &dyn MessageChannel<M>[src]

Upcasts this weak message channel into a reference to the generic MessageChannel trait object

Auto Trait Implementations

impl<A, Rc = Strong> !RefUnwindSafe for Address<A, Rc>[src]

impl<A, Rc> Send for Address<A, Rc>[src]

impl<A, Rc> Sync for Address<A, Rc>[src]

impl<A, Rc> Unpin for Address<A, Rc>[src]

impl<A, Rc = Strong> !UnwindSafe for Address<A, Rc>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.