-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello.rs
43 lines (36 loc) · 1.06 KB
/
hello.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extern crate jsonbox;
use jsonbox::{Client, Error};
use serde::{Deserialize, Serialize};
use std::io;
#[derive(Serialize, Deserialize)]
struct Greeting {
name: String,
message: String,
}
fn main() -> Result<(), Error> {
let client = Client::new("kuy_ed82aef3f93176996146");
let all = client.read().all::<Greeting>()?;
if let Some((record, meta)) = all.first() {
println!(
"Greeting from {} at {}: {}",
record.name.trim(),
meta.created_on.trim(),
record.message.trim(),
);
} else {
println!("No message left, you're the first.");
}
println!("What is your name?");
let mut name = String::new();
let _ = io::stdin().read_line(&mut name);
println!("Leave message for next guest :)");
let mut message = String::new();
let _ = io::stdin().read_line(&mut message);
let data = Greeting {
name: name.trim().to_string(),
message: message.trim().to_string(),
};
let _ = client.create(&data)?;
println!("Thank you!");
Ok(())
}