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

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.

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.

Make a Remote Procedure Call (RPC).

This will send the request to the actor and returns a Rpc Future that will return a response (of type Res), or an error if the receiving actor didn’t respond.

See the rpc module for more details.

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.

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

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.

Change the message type of the actor reference.

Before sending the message this will first change the message into a different type using the mapping 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.

Change the message type of the actor reference.

Before sending the message this will first change the message into a different type using the mapping 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.

Returns a Future that waits until the actor finishes running. Acts similar to a JoinHandle of a thread.

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.

Returns true if self and other send messages to the same actor.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Converts to this type from the input type.

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.