forked from vaind/objectbox-rust
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.rs
More file actions
43 lines (34 loc) · 1012 Bytes
/
Copy pathmain.rs
File metadata and controls
43 lines (34 loc) · 1012 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
extern crate objectbox;
use example::{make_factory_map, make_model, Entity3};
use crate::objectbox::{opt::Opt, store::Store};
fn main() {
let mut model = make_model();
let opt = Opt::from_model(&mut model).expect("crash");
let trait_map = make_factory_map();
let store = Store::new(opt, trait_map).expect("crash");
// box is a reserved keyword use r#box or simply something else
let mut box1 = store.get_box::<Entity3>().expect("crash");
let mut e_before = Entity3 {
id: 0,
hello: "Hello world!".to_string(),
};
let new_id = match box1.put(&mut e_before) {
Err(err) => panic!("{err}"),
Ok(item_id) => item_id,
};
match box1.get(new_id) {
Err(err) => panic!("{err}"),
Ok(found_item) => {
if let Some(object) = found_item {
println!("{}", object.hello);
}
}
}
}
#[cfg(test)]
mod tests {
use serial_test::serial;
#[test]
#[serial]
fn test() {}
}