triblespace_core/patch/
entry.rs1use super::*;
2
3#[derive(Debug)]
5#[repr(C)]
6pub struct Entry<const KEY_LEN: usize, V = ()> {
7 ptr: NonNull<Leaf<KEY_LEN, V>>,
8}
9
10impl<const KEY_LEN: usize> Entry<KEY_LEN> {
11 pub fn new(key: &[u8; KEY_LEN]) -> Self {
13 unsafe {
14 let ptr = Leaf::<KEY_LEN, ()>::new(key, ());
15 Self { ptr }
16 }
17 }
18}
19
20impl<const KEY_LEN: usize, V> Entry<KEY_LEN, V> {
21 pub fn with_value(key: &[u8; KEY_LEN], value: V) -> Self {
23 unsafe {
24 let ptr = Leaf::<KEY_LEN, V>::new(key, value);
25 Self { ptr }
26 }
27 }
28
29 pub fn value(&self) -> &V {
31 unsafe { &self.ptr.as_ref().value }
32 }
33
34 pub(super) fn leaf<O: KeySchema<KEY_LEN>>(&self) -> Head<KEY_LEN, O, V> {
35 unsafe { Head::new(0, Leaf::rc_inc(self.ptr)) }
36 }
37}
38
39impl<const KEY_LEN: usize, V> Clone for Entry<KEY_LEN, V> {
40 fn clone(&self) -> Self {
41 unsafe {
42 Self {
43 ptr: Leaf::rc_inc(self.ptr),
44 }
45 }
46 }
47}
48
49impl<const KEY_LEN: usize, V> Drop for Entry<KEY_LEN, V> {
50 fn drop(&mut self) {
51 unsafe {
52 Leaf::rc_dec(self.ptr);
53 }
54 }
55}