pub struct ActorRegistry { /* private fields */ }Expand description
Thread-safe registry for looking up actors by name.
Actors are registered at spawn time and can be looked up by name from any task. The registry stores type-erased refs; callers must know the actor type to downcast.
Lifecycle: Actors are auto-registered on spawn but NOT auto-unregistered
on stop. Call unregister explicitly when actors
terminate, or accept that stopped actors remain in the registry (their
refs will report is_alive() == false).
Implementations§
Source§impl ActorRegistry
impl ActorRegistry
Sourcepub fn register<R: Clone + Send + Sync + 'static>(
&self,
name: &str,
actor_ref: R,
)
pub fn register<R: Clone + Send + Sync + 'static>( &self, name: &str, actor_ref: R, )
Register an actor ref under a name. Overwrites if name exists.
The ref must be Clone so it can be retrieved via lookup.
Sourcepub fn lookup<R: Clone + 'static>(&self, name: &str) -> Option<R>
pub fn lookup<R: Clone + 'static>(&self, name: &str) -> Option<R>
Look up an actor by name, returning a clone of its ref.
Returns None if not found or if the type doesn’t match.
Sourcepub fn unregister(&self, name: &str) -> bool
pub fn unregister(&self, name: &str) -> bool
Remove an actor from the registry.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ActorRegistry
impl RefUnwindSafe for ActorRegistry
impl Send for ActorRegistry
impl Sync for ActorRegistry
impl Unpin for ActorRegistry
impl UnsafeUnpin for ActorRegistry
impl UnwindSafe for ActorRegistry
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