use std::path::PathBuf;
use crate::{PersistenceConfig, Result, Station};
#[derive(Debug)]
pub struct StationBuilder {
pub(crate) storage_root: PathBuf,
pub(crate) persistence: PersistenceConfig,
}
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(),
}
}
}
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 async fn build(self) -> Result<Station> {
Station::from_builder(self).await
}
}