entrenar/storage/preflight/checks/
mod.rs1mod data_integrity;
4mod environment;
5
6#[cfg(test)]
7mod tests;
8
9use super::{CheckMetadata, CheckResult, CheckType, PreflightContext};
10
11pub(crate) type CheckFn = Box<dyn Fn(&[Vec<f64>], &PreflightContext) -> CheckResult + Send + Sync>;
13
14pub struct PreflightCheck {
16 pub name: String,
18 pub check_type: CheckType,
20 pub description: String,
22 pub required: bool,
24 pub(crate) check_fn: CheckFn,
26}
27
28impl From<&PreflightCheck> for CheckMetadata {
29 fn from(check: &PreflightCheck) -> Self {
30 Self {
31 name: check.name.clone(),
32 check_type: check.check_type.clone(),
33 description: check.description.clone(),
34 required: check.required,
35 }
36 }
37}
38
39impl std::fmt::Debug for PreflightCheck {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 f.debug_struct("PreflightCheck")
42 .field("name", &self.name)
43 .field("check_type", &self.check_type)
44 .field("description", &self.description)
45 .field("required", &self.required)
46 .finish_non_exhaustive()
47 }
48}
49
50impl PreflightCheck {
51 pub fn new<F>(
53 name: impl Into<String>,
54 check_type: CheckType,
55 description: impl Into<String>,
56 check_fn: F,
57 ) -> Self
58 where
59 F: Fn(&[Vec<f64>], &PreflightContext) -> CheckResult + Send + Sync + 'static,
60 {
61 Self {
62 name: name.into(),
63 check_type,
64 description: description.into(),
65 required: true,
66 check_fn: Box::new(check_fn),
67 }
68 }
69
70 pub fn optional(mut self) -> Self {
72 self.required = false;
73 self
74 }
75
76 pub fn run(&self, data: &[Vec<f64>], context: &PreflightContext) -> CheckResult {
78 (self.check_fn)(data, context)
79 }
80}