use super::YfWarning;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum DataQuality {
#[default]
BestEffort,
Strict,
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct YfResponse<T> {
pub data: T,
pub diagnostics: YfDiagnostics,
}
impl<T> YfResponse<T> {
#[must_use]
pub const fn new(data: T, diagnostics: YfDiagnostics) -> Self {
Self { data, diagnostics }
}
#[must_use]
pub const fn is_lossless(&self) -> bool {
self.diagnostics.is_lossless()
}
#[must_use]
pub fn into_data(self) -> T {
self.data
}
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> YfResponse<U> {
YfResponse {
data: f(self.data),
diagnostics: self.diagnostics,
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct YfDiagnostics {
pub warnings: Vec<YfWarning>,
}
impl YfDiagnostics {
#[must_use]
pub const fn new() -> Self {
Self {
warnings: Vec::new(),
}
}
#[must_use]
pub const fn is_lossless(&self) -> bool {
self.warnings.is_empty()
}
#[must_use]
pub const fn len(&self) -> usize {
self.warnings.len()
}
#[must_use]
pub const fn is_empty(&self) -> bool {
self.warnings.is_empty()
}
pub(crate) fn push(&mut self, warning: YfWarning) {
self.warnings.push(warning);
}
pub(crate) fn extend(&mut self, other: Self) {
self.warnings.extend(other.warnings);
}
pub(crate) fn with_key_prefix(mut self, prefix: &str) -> Self {
self.warnings = self
.warnings
.into_iter()
.map(|warning| warning.with_key_prefix(prefix))
.collect();
self
}
}