pub trait ActorRef<A: Actor>:
Clone
+ Send
+ Sync
+ 'static {
// Required methods
fn id(&self) -> ActorId;
fn name(&self) -> String;
fn is_alive(&self) -> bool;
fn stop(&self);
fn tell<M>(&self, msg: M) -> Result<(), ActorSendError>
where A: Handler<M>,
M: Message<Reply = ()>;
fn ask<M>(
&self,
msg: M,
cancel: Option<CancellationToken>,
) -> Result<AskReply<M::Reply>, ActorSendError>
where A: Handler<M>,
M: Message;
fn expand<M, OutputItem>(
&self,
msg: M,
buffer: usize,
batch_config: Option<BatchConfig>,
cancel: Option<CancellationToken>,
) -> Result<BoxStream<OutputItem>, ActorSendError>
where A: ExpandHandler<M, OutputItem>,
M: Send + 'static,
OutputItem: Send + 'static;
fn reduce<InputItem, Reply>(
&self,
input: BoxStream<InputItem>,
buffer: usize,
batch_config: Option<BatchConfig>,
cancel: Option<CancellationToken>,
) -> Result<AskReply<Reply>, ActorSendError>
where A: ReduceHandler<InputItem, Reply>,
InputItem: Send + 'static,
Reply: Send + 'static;
fn transform<InputItem, OutputItem>(
&self,
input: BoxStream<InputItem>,
buffer: usize,
batch_config: Option<BatchConfig>,
cancel: Option<CancellationToken>,
) -> Result<BoxStream<OutputItem>, ActorSendError>
where A: TransformHandler<InputItem, OutputItem>,
InputItem: Send + 'static,
OutputItem: Send + 'static;
// Provided method
fn pending_messages(&self) -> usize { ... }
}Expand description
A reference to a running actor of type A.
ActorRef<A> is typed to the actor struct. This enables
sending any message type M where A: Handler<M>.
Required Methods§
Sourcefn tell<M>(&self, msg: M) -> Result<(), ActorSendError>
fn tell<M>(&self, msg: M) -> Result<(), ActorSendError>
Fire-and-forget: deliver a message to the actor.
The message must have Reply = () (no reply expected).
Sourcefn ask<M>(
&self,
msg: M,
cancel: Option<CancellationToken>,
) -> Result<AskReply<M::Reply>, ActorSendError>
fn ask<M>( &self, msg: M, cancel: Option<CancellationToken>, ) -> Result<AskReply<M::Reply>, ActorSendError>
Request-reply: send a message and await the reply.
Returns an AskReply future that resolves to the handler’s reply.
Usage: let reply = actor.ask(msg, None)?.await?;
Pass a CancellationToken to cooperatively cancel the operation.
Sourcefn expand<M, OutputItem>(
&self,
msg: M,
buffer: usize,
batch_config: Option<BatchConfig>,
cancel: Option<CancellationToken>,
) -> Result<BoxStream<OutputItem>, ActorSendError>
fn expand<M, OutputItem>( &self, msg: M, buffer: usize, batch_config: Option<BatchConfig>, cancel: Option<CancellationToken>, ) -> Result<BoxStream<OutputItem>, ActorSendError>
Request-stream: send a request and receive a stream of responses.
buffer controls the channel capacity (backpressure).
Pass batch_config to enable batching (reduces per-item overhead
for remote actors). None means unbatched per-item delivery.
Pass a CancellationToken to cooperatively cancel the stream.
Sourcefn reduce<InputItem, Reply>(
&self,
input: BoxStream<InputItem>,
buffer: usize,
batch_config: Option<BatchConfig>,
cancel: Option<CancellationToken>,
) -> Result<AskReply<Reply>, ActorSendError>
fn reduce<InputItem, Reply>( &self, input: BoxStream<InputItem>, buffer: usize, batch_config: Option<BatchConfig>, cancel: Option<CancellationToken>, ) -> Result<AskReply<Reply>, ActorSendError>
Client-streaming (feed): stream items to the actor and receive a reply.
The caller provides items via input. The actor consumes them via
StreamReceiver and returns a single reply when the stream ends.
buffer controls the internal channel capacity (backpressure).
Pass batch_config to enable batching (reduces per-item overhead
for remote actors). None means unbatched per-item delivery.
Pass a CancellationToken to cooperatively cancel the feed.
Usage: let reply = actor.reduce::<u64, u64>(input, 8, None, None)?.await?;
Sourcefn transform<InputItem, OutputItem>(
&self,
input: BoxStream<InputItem>,
buffer: usize,
batch_config: Option<BatchConfig>,
cancel: Option<CancellationToken>,
) -> Result<BoxStream<OutputItem>, ActorSendError>where
A: TransformHandler<InputItem, OutputItem>,
InputItem: Send + 'static,
OutputItem: Send + 'static,
fn transform<InputItem, OutputItem>(
&self,
input: BoxStream<InputItem>,
buffer: usize,
batch_config: Option<BatchConfig>,
cancel: Option<CancellationToken>,
) -> Result<BoxStream<OutputItem>, ActorSendError>where
A: TransformHandler<InputItem, OutputItem>,
InputItem: Send + 'static,
OutputItem: Send + 'static,
Transform: stream items to the actor and receive a stream of outputs.
The caller provides items via input. For each input item the actor’s
TransformHandler::handle_transform may push zero or more output items.
When the input stream ends, TransformHandler::on_transform_complete
is called to allow final items to be emitted.
buffer controls the internal channel capacity (backpressure).
Pass batch_config to enable batching on the output stream. Batching
groups output items into vectors by max_items or max_delay,
amortizing serialization and network costs for remote actors.
None means unbatched per-item delivery.
Pass a CancellationToken to cooperatively cancel the transform.
Usage:
let output: BoxStream<String> = actor.transform::<i32, String>(input, 8, None, None)?;Provided Methods§
Sourcefn pending_messages(&self) -> usize
fn pending_messages(&self) -> usize
Approximate number of messages pending in the actor’s mailbox.
This is a best-effort snapshot that may be stale immediately after
reading. Used by PoolRouting::LeastLoaded
to route to the least-busy worker. Returns 0 by default;
adapters that can query their mailbox depth should override this.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.