[−][src]Struct xtra_addons::Address
An Address
is a reference to an actor through which Message
s 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), Address
es are strong. Therefore, when all Address
es
are dropped, the actor will be stopped. In other words, any existing Address
es 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]
A: Actor,
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]
A: Actor,
Functions which apply only to addresses which can either be strong or weak.
impl<A, Rc> Address<A, Rc> where
Rc: RefCounter,
A: Actor,
[src]
Rc: RefCounter,
A: Actor,
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]
A: Handler<M>,
M: Message,
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]
A: Handler<M>,
M: Message,
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]
A: Handler<M>,
M: Message,
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]
A: Handler<M>,
M: Message<Result = K>,
K: Into<KeepRunning> + Send,
S: Stream<Item = M> + Send,
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 map
ped). 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]
Rc: RefCounter,
A: Actor,
impl<A, Rc> Drop for Address<A, Rc> where
Rc: RefCounter,
A: Actor,
[src]
Rc: RefCounter,
A: Actor,
impl<A, M, Rc> MessageChannel<M> for Address<A, Rc> where
Rc: RefCounter,
A: Handler<M>,
M: Message,
[src]
Rc: RefCounter,
A: Handler<M>,
M: Message,
pub fn is_connected(&self) -> bool
[src]
pub fn do_send(&self, message: M) -> Result<(), Disconnected>
[src]
pub fn send(&self, message: M) -> SendFuture<M>
[src]
pub fn attach_stream(
self,
stream: Pin<Box<dyn Stream<Item = M> + Send, Global>>
) -> Pin<Box<dyn Future<Output = ()> + Send, Global>> where
<M as Message>::Result: Into<KeepRunning>,
<M as Message>::Result: Send,
[src]
self,
stream: Pin<Box<dyn Stream<Item = M> + Send, Global>>
) -> Pin<Box<dyn Future<Output = ()> + Send, Global>> where
<M as Message>::Result: Into<KeepRunning>,
<M as Message>::Result: Send,
pub fn clone_channel(&self) -> Box<dyn MessageChannel<M> + 'static, Global>
[src]
pub fn sink(
&self
) -> Box<dyn MessageSink<M, Error = Disconnected> + 'static, Global>
[src]
&self
) -> Box<dyn MessageSink<M, Error = Disconnected> + 'static, Global>
impl<M> PublishExt<M> for Address<Broker<M>> where
M: Message<Result = ()> + Clone,
[src]
M: Message<Result = ()> + Clone,
fn publish<'life0, 'async_trait>(
&'life0 self,
message: M
) -> Pin<Box<dyn Future<Output = Result<(), Disconnected>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
[src]
&'life0 self,
message: M
) -> Pin<Box<dyn Future<Output = Result<(), Disconnected>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
impl<A, M> StrongMessageChannel<M> for Address<A, Strong> where
A: Handler<M>,
M: Message,
[src]
A: Handler<M>,
M: Message,
pub fn downgrade(&self) -> Box<dyn WeakMessageChannel<M> + 'static, Global>
[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
pub fn clone_channel(
&self
) -> Box<dyn StrongMessageChannel<M> + 'static, Global>
[src]
&self
) -> Box<dyn StrongMessageChannel<M> + 'static, Global>
pub fn sink(
&self
) -> Box<dyn StrongMessageSink<M, Error = Disconnected> + 'static, Global>
[src]
&self
) -> Box<dyn StrongMessageSink<M, Error = Disconnected> + 'static, Global>
impl<T, M> SubscribeExt<M> for Address<T> where
T: Handler<M>,
M: Message<Result = ()> + Clone,
[src]
T: Handler<M>,
M: Message<Result = ()> + Clone,
fn subscribe<'life0, 'async_trait>(
&'life0 self,
broker: Address<Broker<M>>
) -> Pin<Box<dyn Future<Output = Result<Subscription<M>, ()>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
[src]
&'life0 self,
broker: Address<Broker<M>>
) -> Pin<Box<dyn Future<Output = Result<Subscription<M>, ()>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
impl<A, M> WeakMessageChannel<M> for Address<A, Weak> where
A: Handler<M>,
M: Message,
[src]
A: Handler<M>,
M: Message,
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
pub fn clone_channel(&self) -> Box<dyn WeakMessageChannel<M> + 'static, Global>
[src]
pub fn sink(
&self
) -> Box<dyn WeakMessageSink<M, Error = Disconnected> + 'static, Global>
[src]
&self
) -> Box<dyn WeakMessageSink<M, Error = Disconnected> + 'static, Global>
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,