MCPcopy Create free account
hub / github.com/Rustixir/darkbird / main

Function main

example/simple.rs:8–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6
7#[tokio::main]
8async fn main() {
9 // path can be '.' in storage::open
10 let path = ".";
11
12 let storage_name = "blackbird";
13 let total_page_size = 1000;
14
15 // ** RamCopies **
16 // Dont log to disk and after shutdown , loss data
17
18 let stype = StorageType::RamCopies;
19
20 // ** DiskCopies **
21 // whole storage operation is in-memory but log to disk,
22 // automatic load whole data after restart, avoid any loss data
23 //
24 // let stype = StorageType::DiskCopies;
25
26 let ops = Options::new(path, storage_name, total_page_size, StorageType::RamCopies, true);
27
28 // Storage is built for high concurrency usage
29 // dont need to Mutex / Rwlock, it is safe for shared between thread
30 //
31 // create storage and initialize other service (reporter, disk_log)
32 //
33 // when calling storage::open, it load whole storage from disk
34 //
35
36 let s1 = Storage::<Pid, User>::open(ops).await.unwrap();
37
38 // insert to memory and send to (disk_log) and (reporter)
39 s1.insert("+98 9370156893".to_owned(), User::new("DanyalMh"))
40 .await
41 .unwrap();
42
43 {
44 let opd = s1.lookup(&"+98 9370156893".to_string()).unwrap();
45 println!("==> {:?}", opd.value());
46 }
47
48 // remove from memory and send to (disk_log) and (reporter)
49 s1.remove("+98 9370156893".to_owned()).await;
50
51
52
53 // iter over storage
54 s1.iter().for_each(|r| {
55 println!("==> {}-{:?}", r.key(), r.value());
56 })
57}
58
59type Pid = String;
60

Callers

nothing calls this directly

Calls 5

insertMethod · 0.45
lookupMethod · 0.45
to_stringMethod · 0.45
removeMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected