-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_world.rs
More file actions
44 lines (36 loc) · 1.03 KB
/
hello_world.rs
File metadata and controls
44 lines (36 loc) · 1.03 KB
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
use bytebox::{byte_box::ByteBox, Deserialize, Serialize};
static APP_NAME: &str = "hello_world";
static BOX_NAME: &str = "my awesome box";
#[derive(Serialize, Deserialize)]
struct MyBox {
special_number: i32,
greet: bool,
name: String,
age: i32,
}
#[cfg(feature = "default")]
fn main() {
let bytebox = ByteBox::default(APP_NAME).expect("Could not create ByteBox");
// write data container to file
bytebox
.set(
BOX_NAME,
&MyBox {
special_number: 12,
greet: true,
name: "John".to_string(),
age: 19,
},
)
.expect("Could not write to ByteBox");
// retrieve data container
let my_box = bytebox
.get::<MyBox>(BOX_NAME)
.expect("Could not read from ByteBox");
// cleanup bytebox
bytebox.delete();
if my_box.greet {
println!("Hello, {}! You are {} years old.", my_box.name, my_box.age);
}
println!("The special number is {}", my_box.special_number);
}