Struct stakker::ActorOwn

source ·
pub struct ActorOwn<A: 'static> { /* private fields */ }
Expand description

An owning ref-counting reference to an actor

This not only keeps a reference to the actor, but it will also automatically terminate the actor when the last owning reference is dropped. This dereferences to a normal Actor reference, so when .clone() is called on it, a normal non-owning reference results. To get another owning reference, use .owned().

Implementations§

source§

impl<A: 'static> ActorOwn<A>

source

pub fn new( core: &mut Core, notify: Ret<StopCause>, parent_id: LogID ) -> ActorOwn<A>

Create a new uninitialised actor of the given type. This is in the Prep state. The reference can be cloned and passed around and used to create Fwd or Ret instances. However all calls to the actor will be delayed until the actor moves into the Ready state.

notify is the StopCause return, which is called when the actor terminates. parent_id is the logging-ID of the parent actor if known, or else 0.

See macros actor! and actor_new! for help with creating and initialising actors.

source

pub fn owned(&self) -> ActorOwn<A>

Create an additional owning reference to this actor. When the last owning reference is dropped, the actor is terminated, even when there are other references active.

source

pub fn kill(&self, s: &mut Stakker, err: Box<dyn Error>)

Kill actor, moving to Zombie state and dropping the contained actor Self value. The actor can never return from the Zombie state. The provided error is used to generate an StopCause::Killed instance, which is passed to the StopCause handler set up when the actor was created.

source

pub fn kill_str(&self, s: &mut Stakker, err: &'static str)

Kill actor, moving to Zombie state and dropping the contained actor Self value. The actor can never return from the Zombie state. The provided error string is used to generate an StopCause::Killed instance, which is passed to the StopCause handler set up when the actor was created.

source

pub fn kill_string(&self, s: &mut Stakker, err: impl Into<String>)

Kill actor, moving to Zombie state and dropping the contained actor Self value. The actor can never return from the Zombie state. The provided error string is used to generate an StopCause::Killed instance, which is passed to the StopCause handler set up when the actor was created.

source

pub fn anon(self) -> ActorOwnAnon

Convert into an anonymous owning reference. See ActorOwnAnon.

Examples found in repository?
examples/actor_own_anon.rs (line 38)
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut stakker = Stakker::new(Instant::now());
    let s = &mut stakker;

    let cat = actor!(s, Cat::init(), ret_nop!());
    call_and_drop(fwd_to!([cat], sound() as ()), cat.anon());

    let dog = actor!(s, Dog::init(), ret_nop!());
    call_and_drop(fwd_to!([dog], sound() as ()), dog.anon());

    s.run(Instant::now(), false);
}

Methods from Deref<Target = Actor<A>>§

source

pub fn is_zombie(&self) -> bool

Check whether the actor is a zombie. Note that this call is less useful than it appears, since the actor may become a zombie between the time you make this call and whatever asynchronous operation follows. It is better to make a call with a ret_to! callback which will send back a None if the actor has died or if the actor drops the Ret for any other reason.

source

pub fn apply_prep( &self, s: &mut Stakker, f: impl FnOnce(&mut Cx<'_, A>) -> Option<A> )

Apply a closure to the actor if it is in the Prep state, otherwise do nothing. This is used to implement deferred prep calls.

source

pub fn apply( &self, s: &mut Stakker, f: impl FnOnce(&mut A, &mut Cx<'_, A>) + 'static )

Apply a closure to the actor when it reaches the Ready state. If the actor is already in the Ready state, the closure is executed immediately. If the actor is in the Prep state, then it queues the operation instead of executing it. This is used to implement deferred ready calls.

source

pub fn query<R>( &self, s: &mut Stakker, f: impl FnOnce(&mut A, &mut Cx<'_, A>) -> R ) -> Option<R>

Query an actor from outside the runtime. This is a synchronous call intended for use when interfacing to external code. Executes the closure on the actor immediately if the actor has a Self value (i.e. is in the Ready state), and returns the result. Otherwise returns None.

source

pub fn id(&self) -> LogID

Get the logging-ID of this actor. If the logger feature isn’t enabled, returns 0.

source

pub fn defer(&self, f: impl FnOnce(&mut Stakker) + 'static)

This may be used to submit items to the Deferrer main queue from a drop handler, without needing a Core reference.

source

pub fn access_deferrer(&self) -> &Deferrer

Used in macros to get a Deferrer reference

source

pub fn access_actor(&self) -> &Self

Used in macros to get an Actor reference

source

pub fn access_log_id(&self) -> LogID

Used in macros to get the actor’s logging-ID. If the logger feature isn’t enabled, returns 0.

Trait Implementations§

source§

impl<A: 'static> Deref for ActorOwn<A>

§

type Target = Actor<A>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Actor<A>

Dereferences the value.
source§

impl<A: 'static> DerefMut for ActorOwn<A>

source§

fn deref_mut(&mut self) -> &mut Actor<A>

Mutably dereferences the value.
source§

impl<A: 'static> Drop for ActorOwn<A>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<A> !RefUnwindSafe for ActorOwn<A>

§

impl<A> !Send for ActorOwn<A>

§

impl<A> !Sync for ActorOwn<A>

§

impl<A> Unpin for ActorOwn<A>

§

impl<A> !UnwindSafe for ActorOwn<A>

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.