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 serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
struct Message {
@ -18,14 +18,9 @@ enum Body {
node_ids: Vec<String>,
},
#[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
);
}
_ => (),
}
}
}