use crate::config::{ErrorMode, LoadOptions, MergeStrategy};
use crate::domain::Format;
use super::Loader;
#[derive(Debug, Clone, Default)]
pub struct LoaderBuilder {
options: Option<LoadOptions>,
default_format: Option<Format>,
}
impl LoaderBuilder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn options(mut self, options: LoadOptions) -> Self {
self.options = Some(options);
self
}
#[must_use]
pub fn merge_strategy(mut self, strategy: MergeStrategy) -> Self {
let mut options = self.options.unwrap_or_default();
options.merge_strategy = strategy;
self.options = Some(options);
self
}
#[must_use]
pub fn fail_fast(mut self, fail_fast: bool) -> Self {
let mut options = self.options.unwrap_or_default();
options.error_mode = ErrorMode::from_fail_fast(fail_fast);
self.options = Some(options);
self
}
#[must_use]
pub const fn default_format(mut self, format: Format) -> Self {
self.default_format = Some(format);
self
}
#[must_use]
pub fn build(self) -> Loader {
Loader {
options: self.options.unwrap_or_default(),
default_format: self.default_format,
}
}
}