Struct simple_actor::Actor
source · [−]pub struct Actor<T: 'static + Send>(_);Expand description
Actor wrapping a state.
Cloning the actor provides an handle to the same actor.
Implementations
sourceimpl<T: 'static + Send> Actor<T>
impl<T: 'static + Send> Actor<T>
sourcepub fn new(state: T) -> (Self, impl Future<Output = ()>)
pub fn new(state: T) -> (Self, impl Future<Output = ()>)
Creates a new Actor with default inbound channel capacity (1024).
Returned future must be spawned in an async executor.
sourcepub fn new_with_capacity(
state: T,
capacity: usize
) -> (Self, impl Future<Output = ()>)
pub fn new_with_capacity(
state: T,
capacity: usize
) -> (Self, impl Future<Output = ()>)
Creates a new Actor with given capacity for its inbound channel.
Returned future must be spawned in an async executor.
sourcepub fn invoke_async<F, R>(&self, invoke: F) -> impl Future<Output = Option<R>> where
F: for<'a> FnOnce(&'a mut T) -> Pin<Box<dyn Future<Output = R> + Send + 'a>> + Send + 'static,
R: 'static + Send,
pub fn invoke_async<F, R>(&self, invoke: F) -> impl Future<Output = Option<R>> where
F: for<'a> FnOnce(&'a mut T) -> Pin<Box<dyn Future<Output = R> + Send + 'a>> + Send + 'static,
R: 'static + Send,
Interacts with the state using a closure returning a future. This future holds the mutable reference to the state, and prevents the actor to process further invokes until this future ends.
The future needs to be boxed using [futures::FutureExt::boxed].
Returns None if the actor is no longer running.
Trait Implementations
impl<T: 'static + Send> Eq for Actor<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for Actor<T>
impl<T> Send for Actor<T>
impl<T> Sync for Actor<T>
impl<T> Unpin for Actor<T>
impl<T> !UnwindSafe for Actor<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more