1use super::PartitionKey;
6use lsm_tree::{UserKey, UserValue, ValueType};
7
8pub struct InnerItem {
12 pub key: UserKey,
16
17 pub value: UserValue,
21
22 pub value_type: ValueType,
24}
25
26unsafe impl Sync for InnerItem {}
27unsafe impl Send for InnerItem {}
28
29#[derive(Clone, PartialEq, Eq)]
31pub struct Item {
32 pub partition: PartitionKey,
36
37 pub key: UserKey,
41
42 pub value: UserValue,
46
47 pub value_type: ValueType,
49}
50
51impl std::fmt::Debug for Item {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 write!(
54 f,
55 "{}:{:?}:{} => {:?}",
56 self.partition,
57 self.key,
58 match self.value_type {
59 ValueType::Value => "V",
60 ValueType::Tombstone => "T",
61 ValueType::WeakTombstone => "W",
62 },
63 self.value
64 )
65 }
66}
67
68impl Item {
69 pub fn new<P: Into<PartitionKey>, K: Into<UserKey>, V: Into<UserValue>>(
73 partition: P,
74 key: K,
75 value: V,
76 value_type: ValueType,
77 ) -> Self {
78 let p = partition.into();
79 let k = key.into();
80 let v = value.into();
81
82 assert!(!p.is_empty());
83 assert!(!k.is_empty());
84
85 assert!(u8::try_from(p.len()).is_ok(), "Partition name too long");
86 assert!(
87 u16::try_from(k.len()).is_ok(),
88 "Keys can be up to 65535 bytes long"
89 );
90 assert!(
91 u32::try_from(v.len()).is_ok(),
92 "Values can be up to 2^32 bytes long"
93 );
94
95 Self {
96 partition: p,
97 key: k,
98 value: v,
99 value_type,
100 }
101 }
102}