mod data_integrity;
mod environment;
#[cfg(test)]
mod tests;
use super::{CheckMetadata, CheckResult, CheckType, PreflightContext};
pub(crate) type CheckFn = Box<dyn Fn(&[Vec<f64>], &PreflightContext) -> CheckResult + Send + Sync>;
pub struct PreflightCheck {
pub name: String,
pub check_type: CheckType,
pub description: String,
pub required: bool,
pub(crate) check_fn: CheckFn,
}
impl From<&PreflightCheck> for CheckMetadata {
fn from(check: &PreflightCheck) -> Self {
Self {
name: check.name.clone(),
check_type: check.check_type.clone(),
description: check.description.clone(),
required: check.required,
}
}
}
impl std::fmt::Debug for PreflightCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PreflightCheck")
.field("name", &self.name)
.field("check_type", &self.check_type)
.field("description", &self.description)
.field("required", &self.required)
.finish_non_exhaustive()
}
}
impl PreflightCheck {
pub fn new<F>(
name: impl Into<String>,
check_type: CheckType,
description: impl Into<String>,
check_fn: F,
) -> Self
where
F: Fn(&[Vec<f64>], &PreflightContext) -> CheckResult + Send + Sync + 'static,
{
Self {
name: name.into(),
check_type,
description: description.into(),
required: true,
check_fn: Box::new(check_fn),
}
}
pub fn optional(mut self) -> Self {
self.required = false;
self
}
pub fn run(&self, data: &[Vec<f64>], context: &PreflightContext) -> CheckResult {
(self.check_fn)(data, context)
}
}