Expand description
Thread-local actor registry with lifetime-safe access guards.
§Design
The actor registry stores actors in thread-local storage and provides access via
ActorRef<T> guards. This design addresses several constraints:
- Use-after-free prevention:
ActorRefholds anRcclone, keeping the actor alive even if removed from the registry while the guard exists. - Re-entrant callbacks: Message handlers frequently call back into the registry
to access other actors. Unlike
RefCell-style borrow tracking, multipleActorRefguards can exist simultaneously without panicking. - No
'staticlifetime lie: Previous designs returned&'static mut T, which didn’t reflect actual validity. The guard-based approach ties the borrow to the guard’s lifetime.
§Limitations
- Aliasing not prevented: Two guards can exist for the same actor simultaneously, allowing aliased mutable access. This is technically undefined behavior but is required by the re-entrant callback pattern. Higher-level discipline is required.
- Thread-local only: Guards must not be sent across threads.
Structs§
- Actor
Ref - A guard providing mutable access to an actor.
- Actor
Registry - Registry for storing actors.
Functions§
- actor_
count - Returns the number of registered actors.
- actor_
exists - Checks if an actor with the
idexists in the registry. - get_
actor - get_
actor_ registry - get_
actor_ unchecked - Returns a guard providing mutable access to the registered actor of type
T. - register_
actor - Registers an actor.
- try_
get_ actor_ unchecked - Attempts to get a guard providing mutable access to the registered actor.