use std::ops::ControlFlow; #[derive(Debug)] pub enum Request { Add(u32, u32), Croak } #[derive(Debug, PartialEq, Eq)] pub enum Reply { Sum(u64), OkIWillCroak } pub struct ThreadedServer {} impl ump_server::ThreadedHandler for ThreadedServer { fn proc_req( &mut self, msg: Request, rctx: ump_server::ReplyContext ) -> ControlFlow { match msg { Request::Add(a, b) => { rctx.reply(Reply::Sum(u64::from(a + b))).unwrap(); ControlFlow::Continue(()) } Request::Croak => { rctx.reply(Reply::OkIWillCroak).unwrap(); ControlFlow::Break(42) } } } } #[cfg(feature = "tokio")] pub struct AsyncServer {} #[ump_server::async_trait] impl ump_server::AsyncHandler for AsyncServer { async fn proc_req( &mut self, msg: Request, rctx: ump_server::ReplyContext ) -> ControlFlow { match msg { Request::Add(a, b) => { rctx.reply(Reply::Sum(u64::from(a + b))).unwrap(); ControlFlow::Continue(()) } Request::Croak => { rctx.reply(Reply::OkIWillCroak).unwrap(); ControlFlow::Break(42) } } } } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :