pub struct Endpoint<A: Actor> { /* private fields */ }Expand description
The primary handle for interacting with an actor.
Endpoint<A> is generic over actor type A, providing compile-time
guarantees that the actor can handle the message being sent. Endpoints
are cheap to clone and can be shared across tasks.
Under the hood, an endpoint is either local (in-memory channel) or remote (serializes over QUIC). The caller never knows which — the API is identical.
§Examples
// Obtain from system.start() or system.lookup()
let counter = system.start("counter/0", Counter, CounterState { count: 0 });
// Send a sync message
let count = counter.send(Increment { amount: 5 }).await?;
// Send an async message
let data = counter.send_async(FetchData { key: "x".into() }).await?;
// Clone and share across tasks
let counter2 = counter.clone();
tokio::spawn(async move {
counter2.send(Increment { amount: 1 }).await.ok();
});Implementations§
Source§impl<A: Actor + 'static> Endpoint<A>
impl<A: Actor + 'static> Endpoint<A>
Sourcepub async fn send<M>(&self, message: M) -> Result<M::Result, SendError>
pub async fn send<M>(&self, message: M) -> Result<M::Result, SendError>
Send a message to the actor. Identical API for local and remote.
Compile-time checked:
Amust implementHandler<M>Mmust implementRemoteMessage(serializable)
For local actors: uses the envelope pattern (zero serialization cost). For remote actors: serializes, sends over wire, awaits response.
§Examples
let count = counter.send(Increment { amount: 5 }).await?;
// Error handling
match counter.send(Increment { amount: 1 }).await {
Ok(new_count) => println!("Count: {new_count}"),
Err(SendError::MailboxClosed) => println!("Actor stopped"),
Err(e) => println!("Send failed: {e}"),
}Sourcepub async fn send_async<M>(&self, message: M) -> Result<M::Result, SendError>
pub async fn send_async<M>(&self, message: M) -> Result<M::Result, SendError>
Send a message to an async handler. Identical API for local and remote.
Like send but dispatches through AsyncHandler<M> so the
handler can .await inside its body.
§Examples
// For actors that implement AsyncHandler<FetchData>
let data = endpoint.send_async(FetchData { key: "users".into() }).await?;Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for Endpoint<A>
impl<A> RefUnwindSafe for Endpoint<A>
impl<A> Send for Endpoint<A>
impl<A> Sync for Endpoint<A>
impl<A> Unpin for Endpoint<A>
impl<A> UnsafeUnpin for Endpoint<A>
impl<A> UnwindSafe for Endpoint<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more