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>

source

pub fn new() -> Self

Create a new ActorOwnSlab

source

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.

source

pub fn len(&self) -> usize

Returns the number of actors held in the slab

source

pub fn is_empty(&self) -> bool

Returns true if there are no values left in the slab

Trait Implementations§

source§

impl<T> Default for ActorOwnSlab<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a, T> IntoIterator for &'a ActorOwnSlab<T>

§

type Item = &'a ActorOwn<T>

The type of the elements being iterated over.
§

type IntoIter = ActorOwnSlabIter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> ActorOwnSlabIter<'a, T>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ActorOwnSlab<T>

§

impl<T> !Send for ActorOwnSlab<T>

§

impl<T> !Sync for ActorOwnSlab<T>

§

impl<T> Unpin for ActorOwnSlab<T>

§

impl<T> !UnwindSafe for ActorOwnSlab<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.