-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathram.rs
28 lines (22 loc) · 780 Bytes
/
ram.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
use hyperbee::Hyperbee;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let hb = Hyperbee::from_ram().await?;
// Insert "world" with key "hello"
hb.put(b"hello", Some(b"world")).await?;
// Get the value for key "hello"
let Some((_seq, Some(val))) = hb.get(b"hello").await? else {
panic!("could not get value");
};
assert_eq!(val, b"world");
// Trying to get a non-exsitant key returns `None`
let res = hb.get(b"no key here").await?;
assert_eq!(res, None);
// Deleting a key returns `true` if it was present
let res = hb.del(b"hello").await?;
assert!(res.is_some());
// Getting deleted key returns `None`
let res = hb.get(b"hello").await?;
assert_eq!(res, None);
Ok(())
}