[][src]Struct stakker::ActorOwnAnon

pub struct ActorOwnAnon(_);

An owning ref-counting reference to an anonymous actor

The purpose of this is to allow owning any one of a class of other actors without knowing the exact type. The only operation this supports is dropping an owning reference to an actor when this value is dropped. It can be used in combination with a Fwd instance to support plugging a variety of different actors into a standard interface, without needing traits. As an alternative, see actor_of_trait!.

Example, using ActorOwn::anon to create the anonymous reference:

struct Cat;
impl Cat {
    fn init(_: CX![]) -> Option<Self> {
        Some(Self)
    }
    fn sound(&mut self, _: CX![]) {
        println!("Miaow");
    }
}

struct Dog;
impl Dog {
    fn init(_: CX![]) -> Option<Self> {
        Some(Self)
    }
    fn sound(&mut self, _: CX![]) {
        println!("Woof");
    }
}

// This function doesn't know whether it's getting a cat or a dog,
// but it can still call it and drop it when it has finished
pub fn call_and_drop(sound: Fwd<()>, own: ActorOwnAnon) {
    fwd!([sound]);
}

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);

Implementations

impl ActorOwnAnon[src]

pub fn new<T: 'static>(actorown: ActorOwn<T>) -> Self[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.