use anyhow::bail; use maelbreaker::{ network::Network, node::Node, payload, runtime::Runtime, types::{Message, Try}, }; payload!( enum Payload { Echo { echo: String }, EchoOk { echo: String }, } ); struct EchoNode { network: Network, } impl Node for EchoNode { fn from_init(network: Network, _: String, _: Vec) -> Self { EchoNode { network } } fn handle_message(&mut self, msg: Message) -> Try { let Payload::Echo { echo } = &msg.body.payload else { bail!("expected echo"); }; let echo = echo.clone(); let reply = msg.into_reply(Payload::EchoOk { echo }); self.network.send(reply) } } fn main() -> Try { Runtime::::run() }