pub trait Hooks {
// Provided methods
fn on_started<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn on_closed<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Used to call arbitrary code on state changes.
§Example
#[derive(Debug, Clone)]
enum Message {
Foo,
Bar,
}
#[vin::actor]
#[vin::handles(Message)]
struct MyActor;
#[async_trait]
impl vin::Hooks for MyActor {
async fn on_started(&self) {
println!("Started!");
}
}