pub struct ThreadedActor<T> { /* private fields */ }
Expand description
An actor that uses an OS thread-per-instance.
This may be useful if the application only needs a few actors and doesn’ otherwise use an async runtime. Or it can be used in an async context if an actor needs to block or is compute intensive and requires its own thread.
Implementations§
Source§impl<T> ThreadedActor<T>
impl<T> ThreadedActor<T>
Source§impl<T> ThreadedActor<T>where
T: Send + 'static,
impl<T> ThreadedActor<T>where
T: Send + 'static,
Sourcepub fn from_state(state: T) -> Self
pub fn from_state(state: T) -> Self
Creates a threaded actor with the specified initial state.
Sourcepub fn cast<F>(&self, f: F)
pub fn cast<F>(&self, f: F)
Send an asynchronous request to the actor.
This queues the request and returns immediately.
Examples found in repository?
examples/threaded_keyval.rs (lines 41-43)
33 pub fn insert<K,V>(&self, key: K, val: V)
34 where
35 K: Into<String>,
36 V: Into<String>,
37 {
38 let key = key.into();
39 let val = val.into();
40
41 self.actor.cast(move |state| {
42 state.insert(key, val);
43 });
44 }
Trait Implementations§
Source§impl<T: Clone> Clone for ThreadedActor<T>
impl<T: Clone> Clone for ThreadedActor<T>
Source§fn clone(&self) -> ThreadedActor<T>
fn clone(&self) -> ThreadedActor<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<T> Freeze for ThreadedActor<T>
impl<T> RefUnwindSafe for ThreadedActor<T>
impl<T> Send for ThreadedActor<T>
impl<T> Sync for ThreadedActor<T>
impl<T> Unpin for ThreadedActor<T>
impl<T> UnwindSafe for ThreadedActor<T>
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