Skip to main content

tuwunel_database/map/
del.rs

1use std::{fmt::Debug, io::Write};
2
3use serde::Serialize;
4use tuwunel_core::{arrayvec::ArrayVec, implement};
5
6use crate::{keyval::KeyBuf, ser};
7
8/// Deletes a serialized key using an owned buffer.
9///
10/// The database serializer encodes the key before raw deletion. Matching
11/// watchers are notified after RocksDB accepts the removal.
12///
13/// # Panics
14///
15/// Panics if serialization fails, RocksDB rejects the deletion, or an uncorked
16/// flush fails.
17#[implement(super::Map)]
18#[inline]
19pub fn del<K>(&self, key: K)
20where
21	K: Serialize + Debug,
22{
23	let mut buf = KeyBuf::new();
24	self.bdel(key, &mut buf);
25}
26
27/// Deletes a serialized key using a fixed-capacity buffer.
28///
29/// `MAX` bounds the complete encoded key without a heap fallback. Matching
30/// watchers are notified after RocksDB accepts the removal.
31///
32/// # Panics
33///
34/// Panics if the encoded key exceeds `MAX`, serialization otherwise fails,
35/// RocksDB rejects the deletion, or an uncorked flush fails.
36#[implement(super::Map)]
37#[inline]
38pub fn adel<const MAX: usize, K>(&self, key: K)
39where
40	K: Serialize + Debug,
41{
42	let mut buf = ArrayVec::<u8, MAX>::new();
43	self.bdel(key, &mut buf);
44}
45
46/// Deletes a serialized key using a caller-supplied buffer.
47///
48/// Serialization appends the encoded key to the supplied buffer, and deletion
49/// uses its full resulting contents. Matching watchers are notified after
50/// RocksDB accepts the removal.
51///
52/// # Panics
53///
54/// Panics if serialization fails, RocksDB rejects the deletion, or an uncorked
55/// flush fails.
56#[implement(super::Map)]
57#[tracing::instrument(skip(self, buf), level = "trace")]
58pub fn bdel<K, B>(&self, key: K, buf: &mut B)
59where
60	K: Serialize + Debug,
61	B: Write + AsRef<[u8]>,
62{
63	let key = ser::serialize(buf, key).expect("failed to serialize deletion key");
64	self.remove(key);
65}