use async_trait::async_trait; use serviceless::{Context, Handler, Message, Service}; #[derive(Debug, Default)] pub struct Service0 {} #[async_trait] impl Service for Service0 { async fn started(&mut self, _ctx: &mut Context) { println!("Started") } } #[derive(Debug)] pub struct U8(pub u8); impl Message for U8 { type Result = U8; } #[async_trait] impl Handler for Service0 { async fn handler(&mut self, message: U8, _ctx: &mut Context) -> U8 { U8(message.0 + 2) } } #[derive(Debug)] pub struct U16(pub u16); impl Message for U16 { type Result = U16; } #[async_trait] impl Handler for Service0 { async fn handler(&mut self, message: U16, _ctx: &mut Context) -> U16 { U16(message.0 + 300) } } #[tokio::main] async fn main() { let ctx = Context::new(); let srv = Service0::default(); let addr = ctx.run(srv); let res = addr.call(U8(8)).await.unwrap(); println!("{:?}", res); let res = addr.call(U16(8)).await.unwrap(); println!("{:?}", res); }