use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct Message { #[serde(flatten)] pub header: MessageHeader, pub body: MaelstromBodyOr, } #[derive(Debug, Serialize, Deserialize)] pub struct MessageHeader { pub src: String, #[serde(rename = "dest")] pub dst: String, } impl MessageHeader { pub fn flip(self) -> Self { Self { src: self.dst, dst: self.src, } } } #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum MaelstromBodyOr { MaelstromBody { #[serde(flatten)] inner: MaelstromBody, }, Other { #[serde(flatten)] inner: B, }, } #[derive(Debug, Serialize, Deserialize)] #[serde(tag = "type")] pub enum MaelstromBody { #[serde(rename = "init")] Init { node_id: String, node_ids: Vec, msg_id: usize, }, #[serde(rename = "init_ok")] InitOk { msg_id: usize, in_reply_to: usize }, }