pub trait Actor: Addr + LifecycleHook {
type Context;
fn new<Id: Into<ActorId> + Send>(
id: Id,
ctx: Self::Context
) -> StrongAddr<Self>;
fn ctx<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = RwLockReadGuard<'_, Self::Context>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
fn ctx_mut<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = RwLockWriteGuard<'_, Self::Context>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
fn start<'life0, 'async_trait>(
self: &'life0 StrongAddr<Self>
) -> Pin<Box<dyn Future<Output = Result<StrongAddr<Self>, StartError>> + Send + 'async_trait>>
where
Self: Sized,
'life0: 'async_trait,
Self: 'async_trait;
}Expand description
Actor trait that all actors must implement.
Implementation is generated by the vin::actor proc macro.
The way actors work in vin is that they live in their own tokio task, polling messages sent
and starting handler tasks for each message received. Shutdown is also synchronized and actors
will be given time to gracefully shutdown before being forcibly closed.
Required Associated Types
Required Methods
sourcefn new<Id: Into<ActorId> + Send>(id: Id, ctx: Self::Context) -> StrongAddr<Self>
fn new<Id: Into<ActorId> + Send>(id: Id, ctx: Self::Context) -> StrongAddr<Self>
Creates a new actor with the given id and context.
sourcefn ctx<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = RwLockReadGuard<'_, Self::Context>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn ctx<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = RwLockReadGuard<'_, Self::Context>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Returns a read lock to the underlying actor context.
sourcefn ctx_mut<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = RwLockWriteGuard<'_, Self::Context>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn ctx_mut<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = RwLockWriteGuard<'_, Self::Context>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Returns a write lock to the underlying actor context.
sourcefn start<'life0, 'async_trait>(
self: &'life0 StrongAddr<Self>
) -> Pin<Box<dyn Future<Output = Result<StrongAddr<Self>, StartError>> + Send + 'async_trait>>where
Self: Sized,
'life0: 'async_trait,
Self: 'async_trait,
fn start<'life0, 'async_trait>(
self: &'life0 StrongAddr<Self>
) -> Pin<Box<dyn Future<Output = Result<StrongAddr<Self>, StartError>> + Send + 'async_trait>>where
Self: Sized,
'life0: 'async_trait,
Self: 'async_trait,
Starts the actor if:
- The ID is not taken
- Hasn’t already been started