use std::path::PathBuf;
use crate::{GapHealConfig, PersistenceConfig, Result, Station};
#[derive(Debug)]
pub struct StationBuilder {
pub(crate) storage_root: PathBuf,
pub(crate) persistence: PersistenceConfig,
pub(crate) warm_start: usize,
pub(crate) gap_heal: GapHealConfig,
}
impl Default for StationBuilder {
fn default() -> Self {
let env_root = std::env::var_os("DIG3_STORAGE_ROOT").map(PathBuf::from);
Self {
storage_root: env_root.unwrap_or_else(|| PathBuf::from("./dig3_storage")),
persistence: PersistenceConfig::default(),
warm_start: 0,
gap_heal: GapHealConfig::default(),
}
}
}
impl StationBuilder {
pub fn new() -> Self { Self::default() }
pub fn storage_root(mut self, root: impl Into<PathBuf>) -> Self {
self.storage_root = root.into();
self
}
pub fn persistence(mut self, cfg: PersistenceConfig) -> Self {
self.persistence = cfg;
self
}
pub fn warm_start(mut self, n: usize) -> Self {
self.warm_start = n;
self
}
pub fn gap_heal(mut self, cfg: GapHealConfig) -> Self {
self.gap_heal = cfg;
self
}
pub async fn build(self) -> Result<Station> {
Station::from_builder(self).await
}
}