forest-filecoin 0.33.2

Rust Filecoin implementation.
Documentation
// Copyright 2019-2026 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::db::{parity_db::ParityDb, parity_db_config::ParityDbConfig};

/// Temporary, self-cleaning ParityDB
#[derive(derive_more::AsRef, derive_more::Deref)]
pub struct TempParityDB {
    #[deref]
    #[as_ref]
    pub db: ParityDb,
    _dir: tempfile::TempDir, // kept for cleaning up during Drop
}

impl TempParityDB {
    /// Creates a new DB in a temporary path that gets wiped out when the
    /// variable gets out of scope.
    pub fn new() -> TempParityDB {
        let dir = tempfile::Builder::new()
            .tempdir()
            .expect("Failed to create temporary path for db.");
        let path = dir.path().join("paritydb");
        let config = ParityDbConfig::default();

        TempParityDB {
            db: ParityDb::open(path, &config).unwrap(),
            _dir: dir,
        }
    }
}