Struct stakker::ActorOwnAnon
source · pub struct ActorOwnAnon(_);
Expand description
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§
Auto Trait Implementations§
impl !RefUnwindSafe for ActorOwnAnon
impl !Send for ActorOwnAnon
impl !Sync for ActorOwnAnon
impl Unpin for ActorOwnAnon
impl !UnwindSafe for ActorOwnAnon
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more