use distributed_systems_flyio::{ types::{EchoMessage, InitMessage, Message}, Malestorm, }; use std::rc::Rc; fn main() { let mut program = Malestorm::default(); program.register("init", |mut msg: Message, program: Rc| { let message_body: InitMessage = serde_json::from_value(msg.body.message_body.take()) .expect("error in parsing message body"); program.set_node_id(message_body.node_id); program.set_nodes(message_body.nodes); msg.body.message_type = "init_ok".into(); match program.reply(msg) { Ok(_) => (), Err(e) => { eprintln!("init: error in writing response: {}", e); } } }); program.register("echo", |mut msg: Message, program: Rc| { let message_body: EchoMessage = serde_json::from_value(msg.body.message_body.take()) .expect("error in parsing message body"); msg.body.message_type = "echo_ok".into(); msg.body.message_body = serde_json::to_value(message_body).unwrap(); match program.reply(msg) { Ok(_) => (), Err(e) => { eprintln!("echo: error in writing response: {}", e); } } }); program.run(); }