pub struct ValRef { /* private fields */ }Expand description
A reference to a value in the storage engine.
Implementations§
Source§impl ValRef
impl ValRef
Sourcepub fn slice(&self) -> &[u8] ⓘ
pub fn slice(&self) -> &[u8] ⓘ
Returns the data as a byte slice.
Examples found in repository?
examples/demo.rs (line 25)
3fn main() -> Result<(), OpCode> {
4 let path = std::env::temp_dir().join("mace");
5 let _ = std::fs::remove_dir_all(&path);
6 let opt = Options::new(path).validate()?;
7 let db = Mace::new(opt)?;
8 let bucket = db.new_bucket("test", BucketOptions::default())?;
9
10 // start a read-write transaction
11 let kv = bucket.begin()?;
12 kv.put("foo", "bar")?;
13 kv.put("fool", "+1s")?;
14 kv.put("foolish", "elder")?;
15
16 // can't create two identical keys
17 let r = kv.put("foolish", "114514").err();
18 assert_eq!(r.unwrap(), OpCode::AbortTx);
19
20 // use `update` for exist key or use `upsert` when unsure
21 let r = kv.update("foolish", "114514");
22 assert!(r.is_ok());
23
24 let r = kv.get("foo")?;
25 assert_eq!(r.slice(), "bar".as_bytes());
26 kv.del("foolish")?;
27 kv.commit()?;
28
29 // rollback
30 let kv = bucket.begin()?;
31 kv.put("mo", "ha")?;
32 drop(kv);
33
34 // start a read-only transaction
35 let view = bucket.view()?;
36 let r = view.get("foo")?;
37 assert_eq!(r.slice(), "bar".as_bytes());
38 let r = view.get("mo");
39 assert_eq!(r.err().unwrap(), OpCode::NotFound);
40
41 // prefix scan
42 let r = view.get("foolish");
43 assert!(r.is_err() && r.err().unwrap() == OpCode::NotFound);
44 let iter = view.seek("foo");
45 assert_eq!(iter.count(), 2);
46
47 Ok(())
48}Trait Implementations§
Auto Trait Implementations§
impl Freeze for ValRef
impl RefUnwindSafe for ValRef
impl Send for ValRef
impl Sync for ValRef
impl Unpin for ValRef
impl UnsafeUnpin for ValRef
impl UnwindSafe for ValRef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more