pub struct ActorRef<M> { /* private fields */ }
Expand description
Actor reference.
An actor reference reference can be used to send messages to an actor, for more details see the module documentation.
Implementations
sourceimpl<M> ActorRef<M>
impl<M> ActorRef<M>
sourcepub fn send<'r, Msg>(&'r self, msg: Msg) -> SendValue<'r, M>ⓘNotable traits for SendValue<'r, M>impl<'r, M> Future for SendValue<'r, M> type Output = Result<(), SendError>;
where
Msg: Into<M>,
pub fn send<'r, Msg>(&'r self, msg: Msg) -> SendValue<'r, M>ⓘNotable traits for SendValue<'r, M>impl<'r, M> Future for SendValue<'r, M> type Output = Result<(), SendError>;
where
Msg: Into<M>,
Send a message to the actor.
See Sending messages and ActorRef::try_send
for more details.
Notes
Mapped actor references, see ActorRef::map
and
ActorRef::try_map
, require an allocation and might be expensive. If
possible try ActorRef::try_send
first, which does not require an
allocation. Regular (i.e. non-mapped) actor references do not require an
allocation.
sourcepub fn try_send<Msg>(&self, msg: Msg) -> Result<(), SendError> where
Msg: Into<M>,
pub fn try_send<Msg>(&self, msg: Msg) -> Result<(), SendError> where
Msg: Into<M>,
Attempt to send a message to the actor.
Some types of actor references can detect errors in sending a message,
however not all actor references can. This means that even if this
methods returns Ok
it does not mean that the message is guaranteed
to be delivered to or handled by the actor.
See Sending messages for more details.
sourcepub fn rpc<'r, Req, Res>(&'r self, request: Req) -> Rpc<'r, M, Res>ⓘNotable traits for Rpc<'r, M, Res>impl<'r, M, Res> Future for Rpc<'r, M, Res> type Output = Result<Res, RpcError>;
where
M: From<RpcMessage<Req, Res>>,
pub fn rpc<'r, Req, Res>(&'r self, request: Req) -> Rpc<'r, M, Res>ⓘNotable traits for Rpc<'r, M, Res>impl<'r, M, Res> Future for Rpc<'r, M, Res> type Output = Result<Res, RpcError>;
where
M: From<RpcMessage<Req, Res>>,
sourcepub fn map<Msg>(self) -> ActorRef<Msg> where
M: From<Msg> + 'static,
Msg: 'static,
pub fn map<Msg>(self) -> ActorRef<Msg> where
M: From<Msg> + 'static,
Msg: 'static,
Change the message type of the actor reference.
Before sending the message this will first change the message into a different type. This is useful when you need to send to different types of actors (using different message types) from a central location.
Notes
This conversion is not cheap, it requires an allocation so use with caution when it comes to performance sensitive code.
Prefer to clone an existing mapped ActorRef
over creating a new one as
that can reuse the allocation mentioned above.
sourcepub fn try_map<Msg>(self) -> ActorRef<Msg> where
M: TryFrom<Msg> + 'static,
Msg: 'static,
pub fn try_map<Msg>(self) -> ActorRef<Msg> where
M: TryFrom<Msg> + 'static,
Msg: 'static,
Much like map
, but uses the TryFrom
trait.
This creates a new actor reference that attempts to map from one message type to another before sending. This is useful when you need to send to different types of actors from a central location.
Notes
Errors converting from one message type to another are turned into
SendError
s.
This conversion is not cheap, it requires an allocation so use with caution when it comes to performance sensitive code.
Prefer to clone an existing mapped ActorRef
over creating a new one as
that can reuse the allocation mentioned above.
sourcepub fn map_fn<Msg, F>(self, map: F) -> ActorRef<Msg> where
F: Fn(Msg) -> M + 'static,
M: 'static,
pub fn map_fn<Msg, F>(self, map: F) -> ActorRef<Msg> where
F: Fn(Msg) -> M + 'static,
M: 'static,
Change the message type of the actor reference.
Before sending the message this will first change the message into a
different type using the map
ping function F
. This is useful when you
need to send to different types of actors (using different message
types) from a central location.
Notes
This conversion is not cheap, it requires an allocation so use with caution when it comes to performance sensitive code.
Prefer to clone an existing mapped ActorRef
over creating a new one as
that can reuse the allocation mentioned above.
sourcepub fn try_map_fn<Msg, F, E>(self, map: F) -> ActorRef<Msg> where
F: Fn(Msg) -> Result<M, E> + 'static,
M: 'static,
pub fn try_map_fn<Msg, F, E>(self, map: F) -> ActorRef<Msg> where
F: Fn(Msg) -> Result<M, E> + 'static,
M: 'static,
Change the message type of the actor reference.
Before sending the message this will first change the message into a
different type using the map
ping function F
. This is useful when you
need to send to different types of actors (using different message
types) from a central location.
Notes
This conversion is not cheap, it requires an allocation so use with caution when it comes to performance sensitive code.
Prefer to clone an existing mapped ActorRef
over creating a new one as
that can reuse the allocation mentioned above.
sourcepub fn join<'r>(&'r self) -> Join<'r, M>ⓘNotable traits for Join<'r, M>impl<'r, M> Future for Join<'r, M> type Output = ();
pub fn join<'r>(&'r self) -> Join<'r, M>ⓘNotable traits for Join<'r, M>impl<'r, M> Future for Join<'r, M> type Output = ();
Returns a Future
that waits until the actor finishes running. Acts
similar to a JoinHandle
of a thread.
sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true
if the actor to which this reference sends to is still
connected.
Notes
Even if this returns true
it doesn’t mean ActorRef::try_send
will
succeeded (even if the inbox isn’t full). There is always a race
condition between using this method and doing something based on it.
This does provide one useful feature: once this returns false
it will
never return true
again. This makes it useful in the use case where
creating a message is expansive, which is wasted if the actor is no
longer running. Thus this should only be used as optimisation to not do
work.
Trait Implementations
sourceimpl<M> Extend<ActorRef<M>> for ActorGroup<M>
impl<M> Extend<ActorRef<M>> for ActorGroup<M>
sourcefn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = ActorRef<M>>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = ActorRef<M>>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<M> From<ActorRef<M>> for ActorGroup<M>
impl<M> From<ActorRef<M>> for ActorGroup<M>
sourcefn from(actor_ref: ActorRef<M>) -> ActorGroup<M>
fn from(actor_ref: ActorRef<M>) -> ActorGroup<M>
Converts to this type from the input type.
sourceimpl<M> FromIterator<ActorRef<M>> for ActorGroup<M>
impl<M> FromIterator<ActorRef<M>> for ActorGroup<M>
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = ActorRef<M>>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = ActorRef<M>>,
Creates a value from an iterator. Read more
Auto Trait Implementations
impl<M> !RefUnwindSafe for ActorRef<M>
impl<M> Send for ActorRef<M> where
M: Send,
impl<M> Sync for ActorRef<M> where
M: Send,
impl<M> Unpin for ActorRef<M>
impl<M> !UnwindSafe for ActorRef<M>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more