block_db/
clear_data_file.rs

1// Authors: Robert Lopez
2
3use super::{error::Error, BlockDB, ConfirmDestructiveAction};
4use crate::util::map_data_file::{map_data_file, map_data_files};
5
6impl BlockDB {
7    /// ⚠️ **CLEARS a `DataFile` of _all_ of its data. This action is irreversible.**
8    ///
9    /// Requires explicitly passing `ConfirmDestructiveAction::IKnowWhatImDoing`
10    /// to confirm intent.
11    ///
12    /// Use with extreme caution.
13    ///
14    /// ---
15    /// - **Atomic**
16    /// - **Corruptible**
17    ///
18    /// ---
19    /// Example
20    /// ```
21    /// let block_db = BlockDB::open("./data", None).await?;
22    ///
23    /// block_db.clear_data_file("3f-6hf", ConfirmDestructiveAction::IKnowWhatImDoing).await?;
24    /// ```
25    pub async fn clear_data_file<S: AsRef<str>>(
26        &self,
27        data_file_id: S,
28        _: ConfirmDestructiveAction,
29    ) -> Result<(), Error> {
30        map_data_file!(self, data_file_id.as_ref(), clear);
31
32        Ok(())
33    }
34
35    /// ⚠️ **CLEARS _all_ `DataFile`s and _all_ of their data. This action is irreversible.**
36    ///
37    /// Requires explicitly passing `ConfirmDestructiveAction::IKnowWhatImDoing`
38    /// to confirm intent.
39    ///
40    /// Use with extreme caution.
41    ///
42    /// ---
43    /// - **Atomic**
44    /// - **Corruptible**
45    ///
46    /// ---
47    /// Example
48    /// ```
49    /// let block_db = BlockDB::open("./data", None).await?;
50    ///
51    /// block_db.clear_data_files(ConfirmDestructiveAction::IKnowWhatImDoing).await?;
52    /// ```
53    pub async fn clear_data_files(&self, _: ConfirmDestructiveAction) -> Result<(), Error> {
54        map_data_files!(self, clear);
55
56        Ok(())
57    }
58}