cargo fmt

This commit is contained in:
Bastian Gruber 2023-05-09 19:39:28 +02:00
parent 962c48afbd
commit de622349b5
No known key found for this signature in database
GPG key ID: BE9F8C772B188CBF

View file

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use std::io::{self, BufRead, Write}; use std::io::{self, BufRead, Write};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct Message { struct Message {
@ -18,14 +18,9 @@ enum Body {
node_ids: Vec<String>, node_ids: Vec<String>,
}, },
#[serde(rename = "init_ok")] #[serde(rename = "init_ok")]
InitOk { InitOk { in_reply_to: u64 },
in_reply_to: u64,
},
#[serde(rename = "echo")] #[serde(rename = "echo")]
Echo { Echo { msg_id: u64, echo: String },
msg_id: u64,
echo: String,
},
#[serde(rename = "echo_ok")] #[serde(rename = "echo_ok")]
EchoOk { EchoOk {
msg_id: u64, msg_id: u64,
@ -44,11 +39,15 @@ fn main() {
let stdin = io::stdin(); let stdin = io::stdin();
let mut stdout = io::stdout(); let mut stdout = io::stdout();
let mut node_id = String::new(); let mut node_id = String::new();
for line in stdin.lock().lines() { for line in stdin.lock().lines() {
let input: Message = serde_json::from_str(&line.unwrap()).unwrap(); let input: Message = serde_json::from_str(&line.unwrap()).unwrap();
match input.body { match input.body {
Body::Init { msg_id, node_id: id, .. } => { Body::Init {
msg_id,
node_id: id,
..
} => {
node_id = id; node_id = id;
let output = Message { let output = Message {
src: node_id.clone(), src: node_id.clone(),
@ -60,7 +59,7 @@ fn main() {
let output_json = serde_json::to_string(&output).unwrap(); let output_json = serde_json::to_string(&output).unwrap();
writeln!(stdout, "{}", output_json).unwrap(); writeln!(stdout, "{}", output_json).unwrap();
stdout.flush().unwrap(); stdout.flush().unwrap();
}, }
Body::Echo { msg_id, echo } => { Body::Echo { msg_id, echo } => {
let output = Message { let output = Message {
src: node_id.clone(), src: node_id.clone(),
@ -74,12 +73,18 @@ fn main() {
let output_json = serde_json::to_string(&output).unwrap(); let output_json = serde_json::to_string(&output).unwrap();
writeln!(stdout, "{}", output_json).unwrap(); writeln!(stdout, "{}", output_json).unwrap();
stdout.flush().unwrap(); stdout.flush().unwrap();
}, }
Body::Error { in_reply_to, code, text } => { Body::Error {
eprintln!("Error received (in_reply_to: {}, code: {}, text: {})", in_reply_to, code, text); in_reply_to,
}, code,
text,
} => {
eprintln!(
"Error received (in_reply_to: {}, code: {}, text: {})",
in_reply_to, code, text
);
}
_ => (), _ => (),
} }
} }
} }