#![cfg(feature = "rocksdb")]
use rocksdb::{Options, DB};
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
pub struct DBPath {
pub path: PathBuf,
}
impl DBPath {
pub fn new(prefix: &str) -> DBPath {
let current_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let path = format!(
"{}.{}.{}",
prefix,
current_time.as_secs(),
current_time.subsec_nanos()
);
DBPath {
path: PathBuf::from(path),
}
}
}
impl Drop for DBPath {
fn drop(&mut self) {
let opts = Options::default();
DB::destroy(&opts, &self.path).unwrap();
}
}
impl AsRef<Path> for DBPath {
fn as_ref(&self) -> &Path {
&self.path
}
}