pub struct ActorRef<A: Actor> {
pub label: String,
pub node_id: String,
/* private fields */
}Expand description
A serializable, typed reference to an actor. Can be embedded in messages and sent across the wire to other nodes.
§Usage
ⓘ
// Create from context inside a handler
let my_ref = ctx.actor_ref();
// Or create directly
let actor_ref = ActorRef::<CounterActor>::new("counter/main", "node-1");
// Serialize and send across the wire (e.g., in a message field)
let encoded = bincode::serde::encode_to_vec(&actor_ref, bincode::config::standard())?;
// On the receiving side, resolve to a live endpoint
let endpoint = actor_ref.resolve(&receptionist).unwrap();
let count = endpoint.send(GetCount).await?;Fields§
§label: String§node_id: StringImplementations§
Source§impl<A: Actor + 'static> ActorRef<A>
impl<A: Actor + 'static> ActorRef<A>
Sourcepub fn new(label: impl Into<String>, node_id: impl Into<String>) -> Self
pub fn new(label: impl Into<String>, node_id: impl Into<String>) -> Self
Create a new ActorRef with the given label and node ID.
Sourcepub fn resolve(&self, receptionist: &Receptionist) -> Option<Endpoint<A>>
pub fn resolve(&self, receptionist: &Receptionist) -> Option<Endpoint<A>>
Resolve this reference to a live Endpoint via the receptionist.
Returns None if the actor is not registered or has a different type.
Trait Implementations§
Source§impl<'de, A: Actor> Deserialize<'de> for ActorRef<A>
impl<'de, A: Actor> Deserialize<'de> for ActorRef<A>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<A> Freeze for ActorRef<A>
impl<A> RefUnwindSafe for ActorRef<A>where
A: RefUnwindSafe,
impl<A> Send for ActorRef<A>
impl<A> Sync for ActorRef<A>where
A: Sync,
impl<A> Unpin for ActorRef<A>where
A: Unpin,
impl<A> UnsafeUnpin for ActorRef<A>
impl<A> UnwindSafe for ActorRef<A>where
A: UnwindSafe,
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
Mutably borrows from an owned value. Read more