use std::sync::Arc; use anyhow::Error; use messagebus::{Builder, Bus, Context, Handler, IntoMessages, Message}; #[derive(Debug, Clone)] pub struct Msg(pub i32); impl Message for Msg {} pub struct Processor { _state: i32, } impl Handler for Processor { type Result = (); type Error = Error; async fn handle( &mut self, _msg: Msg, _ctx: Context, _bus: Bus, ) -> Result, Self::Error> { Ok(()) } async fn handle_error( &mut self, _err: messagebus::Error, _ctx: Context, _bus: messagebus::Bus, ) -> Result + Send + '_, Self::Error> { Ok(None) } async fn finalize(self, _bus: Bus) -> Result<(), Self::Error> { Ok(()) } } struct ProcSpawner; impl Builder for ProcSpawner { type Context = Processor; async fn build( &self, stream_id: u32, _task_id: u32, ) -> Result { Ok(Processor { _state: stream_id as _, }) } } impl Processor { pub async fn spawn(_sid: u32) -> Result<(usize, Self), Error> { Ok((4, Self { _state: 0 })) } pub async fn handler_msg( self: Arc, _sid: u32, _tid: u32, _msg: Msg, ) -> Result<(), Error> { Ok(()) } pub async fn finalize_msg_handler(self: Arc, _sid: u32) -> Result<(), Error> { Ok(()) } } async fn run() { let bus = Bus::new(); bus.register(ProcSpawner).await; } #[tokio::main] async fn main() { run().await }