block-db 0.2.0

Local, multi-threaded, durable byte DB.
Documentation
// Authors: Robert Lopez

use super::{error::Error, BlockDB, ConfirmDestructiveAction};
use crate::util::map_data_file::{map_data_file, map_data_files};

impl BlockDB {
    /// ⚠️ **CLEARS a `DataFile` of _all_ of its data. This action is irreversible.**
    ///
    /// Requires explicitly passing `ConfirmDestructiveAction::IKnowWhatImDoing`
    /// to confirm intent.
    ///
    /// Use with extreme caution.
    ///
    /// ---
    /// - **Atomic**
    /// - **Corruptible**
    ///
    /// ---
    /// Example
    /// ```
    /// let block_db = BlockDB::open("./data", None).await?;
    ///
    /// block_db.clear_data_file("3f-6hf", ConfirmDestructiveAction::IKnowWhatImDoing).await?;
    /// ```
    pub async fn clear_data_file<S: AsRef<str>>(
        &self,
        data_file_id: S,
        _: ConfirmDestructiveAction,
    ) -> Result<(), Error> {
        map_data_file!(self, data_file_id.as_ref(), clear);

        Ok(())
    }

    /// ⚠️ **CLEARS _all_ `DataFile`s and _all_ of their data. This action is irreversible.**
    ///
    /// Requires explicitly passing `ConfirmDestructiveAction::IKnowWhatImDoing`
    /// to confirm intent.
    ///
    /// Use with extreme caution.
    ///
    /// ---
    /// - **Atomic**
    /// - **Corruptible**
    ///
    /// ---
    /// Example
    /// ```
    /// let block_db = BlockDB::open("./data", None).await?;
    ///
    /// block_db.clear_data_files(ConfirmDestructiveAction::IKnowWhatImDoing).await?;
    /// ```
    pub async fn clear_data_files(&self, _: ConfirmDestructiveAction) -> Result<(), Error> {
        map_data_files!(self, clear);

        Ok(())
    }
}