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