Skip to main content

tuwunel_database/map/
clear.rs

1use std::sync::Arc;
2
3use futures::{Stream, TryStreamExt};
4use tuwunel_core::{
5	Result, implement,
6	utils::stream::{ReadyExt, TryIgnore},
7};
8
9use crate::keyval::Key;
10
11/// Delete all data stored in this map. !!! USE WITH CAUTION !!!
12///
13/// See for_clear() with additional details.
14#[implement(super::Map)]
15#[tracing::instrument(level = "trace")]
16pub async fn clear(self: &Arc<Self>) {
17	self.for_clear()
18		.ignore_err()
19		.ready_for_each(|_| ())
20		.await;
21}
22
23/// Delete all data stored in this map. !!! USE WITH CAUTION !!!
24///
25/// Provides stream of keys undergoing deletion along with any errors.
26///
27/// Note this operation applies to a snapshot of the data when invoked.
28/// Additional data written during or after this call may be missed.
29#[implement(super::Map)]
30#[tracing::instrument(level = "trace")]
31pub fn for_clear(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send {
32	self.raw_keys().inspect_ok(|key| self.remove(key))
33}