use std::fmt;
use crate::observation_dataset::ObsDataset;
#[cfg(any(feature = "ades", feature = "mpc_80_col"))]
use camino::Utf8PathBuf;
#[derive(Debug)]
pub enum LoadWarning {
#[cfg(feature = "ades")]
AdesFile {
path: Utf8PathBuf,
error: crate::io::ades::AdesError,
},
#[cfg(feature = "mpc_80_col")]
MpcFile {
path: Utf8PathBuf,
error: crate::io::mpc_80_col::Mpc80ColError,
},
}
impl fmt::Display for LoadWarning {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[allow(unreachable_patterns)]
match self {
#[cfg(feature = "ades")]
LoadWarning::AdesFile { path, error } => {
write!(f, "ADES file '{path}' skipped: {error}")
}
#[cfg(feature = "mpc_80_col")]
LoadWarning::MpcFile { path, error } => {
write!(f, "MPC 80-col file '{path}' skipped: {error}")
}
#[allow(unreachable_patterns)]
_ => write!(f, ""),
}
}
}
#[derive(Default)]
pub struct ObsDatasetBuilder {
pub(crate) dataset: Option<ObsDataset>,
pub(crate) warnings: Vec<LoadWarning>,
}
impl ObsDatasetBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn from_dataset(dataset: ObsDataset) -> Self {
Self {
dataset: Some(dataset),
warnings: Vec::new(),
}
}
pub fn build(self) -> (ObsDataset, Vec<LoadWarning>) {
let dataset = self.dataset.unwrap_or_else(ObsDataset::empty);
(dataset, self.warnings)
}
}