Struct crossbus::register::ActorRegister
source · pub struct ActorRegister { /* private fields */ }Expand description
A record will registered into REGISTER for
future use (Create/Read/Update/Delete)
each record contains
id:usize, the unique identifier of the actor.actor: the type implementedAcotrtraitsealed:AtomicBool, status marker indicates the actor is mutably borrowed or nottype_id: the type id ofAcotrtrait implementormessage_id: the type id of the type implementedMessagetraitname:String, the name of the registered actor, the default format isAcotr-{id}, customize it with set_name.closed:AtomicBool, status marker indicates the actor is closed or not
Implementations§
source§impl ActorRegister
impl ActorRegister
sourcepub fn message_id(&self) -> TypeId
pub fn message_id(&self) -> TypeId
the TypeId of the Actor::Message
sourcepub fn set_closed(&self, state: bool)
pub fn set_closed(&self, state: bool)
set the actor is closed
sourcepub fn is_sealed(&self) -> bool
pub fn is_sealed(&self) -> bool
indicator that whether the Actor is being downcasted to Actor and mutating
sourcepub fn downcast_ref<A: Actor>(&self) -> Option<&A>
pub fn downcast_ref<A: Actor>(&self) -> Option<&A>
downcast the type Actor type &A
sourcepub fn downcast_mut<A: Actor, F>(&self, f: F) -> Option<bool>where
F: FnMut(&mut A) -> Result<(), ()>,
pub fn downcast_mut<A: Actor, F>(&self, f: F) -> Option<bool>where F: FnMut(&mut A) -> Result<(), ()>,
downcast the type Actor type &mut A
then mutate it with the function f
and return
None: downcast failedSome(false): downcasted andfreturnErr(_)Some(true): downcasted andfreturnOk(_)
the underlying actor will be guarded when downcasted no more mutable access is allowed during downcasted
Trait Implementations§
source§impl Debug for ActorRegister
impl Debug for ActorRegister
impl Send for ActorRegister
Safety: since it is guardted with AtomicBool
for generic A: Actor
- nothing changes to the Inner data when downcasted to &A,
- seal the inner to deny more than one access when downcasted to &mut A
So it is safe to send &A between threads
impl Sync for ActorRegister
Safety: since it is guardted with AtomicBool
for generic A: Actor
- nothing changes to the Inner data when downcasted to &A,
- seal the inner to deny more than one access when downcasted to &mut A
So it is safe to send &A between threads