Struct stakker::ActorOwnAnon [−][src]
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]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Any for T where
T: Any,
[src]
T: Any,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,