Skip to main content

tuwunel_database/map/
remove.rs

1use std::fmt::Debug;
2
3use tuwunel_core::implement;
4
5use crate::util::or_else;
6
7/// Deletes a raw key from this map.
8///
9/// The removal uses the map's configured options, flushes immediately when the
10/// engine is uncorked, and then notifies matching watchers. When the engine is
11/// corked, the surrounding cork controls flushing.
12///
13/// # Panics
14///
15/// Panics if RocksDB rejects the deletion or an uncorked flush fails.
16#[implement(super::Map)]
17#[tracing::instrument(skip(self, key), fields(%self), level = "trace")]
18pub fn remove<K>(&self, key: &K)
19where
20	K: AsRef<[u8]> + ?Sized + Debug,
21{
22	let write_options = &self.write_options;
23	self.engine
24		.db
25		.delete_cf_opt(&self.cf(), key, write_options)
26		.or_else(or_else)
27		.expect("database remove error");
28
29	if !self.engine.corked() {
30		self.engine.flush().expect("database flush error");
31	}
32
33	self.notify(key.as_ref());
34}