use std::path::PathBuf;
use std::sync::Arc;
use super::config::{Storage, TreeConfig};
use super::tree::Tree;
use crate::api::errors::Result;
use crate::store::backend::Backend;
#[derive(Debug, Clone)]
#[must_use = "TreeBuilder is consumed by `.open()` / `.open_with_backend()`; chained setters return a fresh builder you must use"]
pub struct TreeBuilder {
cfg: TreeConfig,
}
impl TreeBuilder {
pub fn new<P: Into<PathBuf>>(data_dir: P) -> Self {
Self {
cfg: TreeConfig::new(data_dir),
}
}
pub fn memory(mut self) -> Self {
self.cfg.storage = Storage::Memory;
self
}
pub fn buffer_pool_size(mut self, n: usize) -> Self {
self.cfg.buffer_pool_size = n;
self
}
pub fn wal_sync_on_commit(mut self, on: bool) -> Self {
self.cfg.wal_sync_on_commit = on;
self
}
pub fn checkpoint_byte_interval(mut self, bytes: u64) -> Self {
self.cfg.checkpoint_byte_interval = bytes;
self
}
pub fn open(self) -> Result<Tree> {
Tree::open(self.cfg)
}
pub fn open_with_backend(self, backend: Arc<dyn Backend>) -> Result<Tree> {
Tree::open_with_backend(self.cfg, backend)
}
}