Struct stakker::ActorOwnSlab
source · pub struct ActorOwnSlab<T: 'static> { /* private fields */ }
Expand description
A set of owning actor references
This type may be convenient when an actor will have many children of the same type and the parent doesn’t need to differentiate between them, nor access them with a key. This type keeps track of them and automatically takes care of removing each child actor from the set when it terminates. It also allows iterating through them in case the parent needs to make a call to all child actors.
The actor_in_slab!
macro provides a wrapper around this to
make its use more readable.
However for more complicated cases, you might want to do all this
in your own code instead of using this type. For example for the
case where you already have a key that you want to associate with
the child actor, and you want to use that key to get hold of the
actor reference, in that case you need a HashMap
, not a slab.
Note that this doesn’t expose the usize
slab key. This is
intentional. Cases where the slab key would be useful are better
handled in user code, i.e. they would probably need a HashMap
,
and in that case the ActorOwn
would be better kept in that
HashMap
instead of in this slab.
Implementations§
source§impl<T: 'static> ActorOwnSlab<T>
impl<T: 'static> ActorOwnSlab<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ActorOwnSlab
sourcepub fn add<P>(
&mut self,
core: &mut Core,
parent: Actor<P>,
get_slab: impl for<'a> FnOnce(&'a mut P) -> &'a mut Self + 'static,
notify: Ret<StopCause>
) -> Actor<T>
pub fn add<P>( &mut self, core: &mut Core, parent: Actor<P>, get_slab: impl for<'a> FnOnce(&'a mut P) -> &'a mut Self + 'static, notify: Ret<StopCause> ) -> Actor<T>
Create an actor whose ActorOwn
is stored in the slab, with
a termination notification handler which automatically removes
it from this slab when it fails or terminates. get_slab
would typically be |this| this.children
, assuming children
is what the ActorOwnSlab
is called in the actor’s state.
The notify
handler is called as normal with the
StopCause
.
This call does the same as actor_new!
, i.e. it creates the
actor but does not initialise it. It returns an Actor
reference which can be used to initialise the actor.