-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_world.rs
More file actions
49 lines (39 loc) · 969 Bytes
/
hello_world.rs
File metadata and controls
49 lines (39 loc) · 969 Bytes
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
44
45
46
47
48
49
use std::path::PathBuf;
use bytebox::ByteBox;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct MyBox {
special_number: i32,
greet: bool,
name: String,
age: i32,
}
impl ByteBox<true> for MyBox {
fn path(&self) -> PathBuf {
PathBuf::from("my_box.bin")
}
}
fn main() {
let my_box = MyBox {
special_number: 12,
greet: true,
name: "John".to_string(),
age: 19,
};
my_box.save().expect("Could not save ByteBox");
let mut loaded_box = MyBox {
special_number: 0,
greet: false,
name: String::new(),
age: 0,
};
loaded_box.load().expect("Could not load ByteBox");
if loaded_box.greet {
println!(
"Hello, {}! You are {} years old.",
loaded_box.name, loaded_box.age
);
}
println!("The special number is {}", loaded_box.special_number);
loaded_box.delete().unwrap();
}