From de622349b57debcdf5d1a463478ba9358057d474 Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Tue, 9 May 2023 19:39:28 +0200 Subject: [PATCH] cargo fmt --- 01-echo/src/main.rs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/01-echo/src/main.rs b/01-echo/src/main.rs index 6bbb77d..52b1765 100644 --- a/01-echo/src/main.rs +++ b/01-echo/src/main.rs @@ -1,5 +1,5 @@ +use serde::{Deserialize, Serialize}; use std::io::{self, BufRead, Write}; -use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] struct Message { @@ -18,14 +18,9 @@ enum Body { node_ids: Vec, }, #[serde(rename = "init_ok")] - InitOk { - in_reply_to: u64, - }, + InitOk { in_reply_to: u64 }, #[serde(rename = "echo")] - Echo { - msg_id: u64, - echo: String, - }, + Echo { msg_id: u64, echo: String }, #[serde(rename = "echo_ok")] EchoOk { msg_id: u64, @@ -44,11 +39,15 @@ fn main() { let stdin = io::stdin(); let mut stdout = io::stdout(); let mut node_id = String::new(); - + for line in stdin.lock().lines() { let input: Message = serde_json::from_str(&line.unwrap()).unwrap(); match input.body { - Body::Init { msg_id, node_id: id, .. } => { + Body::Init { + msg_id, + node_id: id, + .. + } => { node_id = id; let output = Message { src: node_id.clone(), @@ -60,7 +59,7 @@ fn main() { let output_json = serde_json::to_string(&output).unwrap(); writeln!(stdout, "{}", output_json).unwrap(); stdout.flush().unwrap(); - }, + } Body::Echo { msg_id, echo } => { let output = Message { src: node_id.clone(), @@ -74,12 +73,18 @@ fn main() { let output_json = serde_json::to_string(&output).unwrap(); writeln!(stdout, "{}", output_json).unwrap(); stdout.flush().unwrap(); - }, - Body::Error { in_reply_to, code, text } => { - eprintln!("Error received (in_reply_to: {}, code: {}, text: {})", in_reply_to, code, text); - }, + } + Body::Error { + in_reply_to, + code, + text, + } => { + eprintln!( + "Error received (in_reply_to: {}, code: {}, text: {})", + in_reply_to, code, text + ); + } _ => (), } } } -