pub trait Actor:
Sized
+ Send
+ 'static {
// Provided methods
fn started(&mut self, _ctx: &mut Context<Self>) { ... }
fn stopped(&mut self) { ... }
fn start(self) -> Addr<Self> { ... }
}
Expand description
An asynchronous actor.
An arbitrary type implementing the Actor trait will become a sampr actor. Use Actor::start() to start receiving messages for the actor. Once started, the actor object will be moved to a tokio::task.
The application should then use messages to interact with this actor. Messages can be sent using this actor’s Addr. Access to the actor while processing those messages will be granted through a mutable reference in the respective handler functions and callbacks. Additionally, those will have a reference to the actor’s Context at hand to interact with the actor and the actor’s tokio::task.
§Example
struct MyActor;
impl sampr::Actor for MyActor {}
Provided Methods§
Sourcefn started(&mut self, _ctx: &mut Context<Self>)
fn started(&mut self, _ctx: &mut Context<Self>)
Called in the context of the actor’s tokio::task
when the actor is started .
The default implementation of this function does nothing.
Sourcefn stopped(&mut self)
fn stopped(&mut self)
Called in the context of the actor’s tokio::task
when the actor is stopped.
The default implementation of this function does nothing.
Sourcefn start(self) -> Addr<Self>
fn start(self) -> Addr<Self>
Start the actor.
By starting, the actor object is moved to its own tokio::task
and starts receiving
messages.
Please note: The underlying actor’s message queue (i.e., a mpsc::channel()) is currently limited to 10 messages. This, however, is not a limiting factor as sending a message through Addr::send() will await the message’s result anyways, hence the sending actor will wait regardless of whether the receiver’s message queue has reached its capacity.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.