cargo fmt
This commit is contained in:
parent
962c48afbd
commit
de622349b5
1 changed files with 21 additions and 16 deletions
|
|
@ -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
|
||||
);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue