#![feature(impl_trait_in_assoc_type)] use std::sync::Arc; use messagebus::{Builder, Bus, Error, Handler, IntoMessage, 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 IntoMessage = impl IntoMessage; type HandleFut<'a> = impl futures::Future> + 'a; type FinalizeFut<'a> = impl futures::Future> + 'a; fn handle(&mut self, msg: Msg, _stream_id: u32, _task_id: u32) -> Self::HandleFut<'_> { async move { Ok(()) } } fn finalize<'a>(self) -> Self::FinalizeFut<'a> { async move { Ok(()) } } } struct ProcSpawner; impl Builder for ProcSpawner { type Context = Processor; type BuildFut<'a> = impl futures::Future> + 'a; fn build(&self, stream_id: u32, _task_id: u32) -> Self::BuildFut<'_> { async move { 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 }