1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
use serde::Serialize; #[derive(Debug, Clone, Serialize)] pub struct ExpResult { pub descr: String, pub path: Vec<String>, pub index: Vec<usize>, pub met_flag: bool, } #[derive(Debug, Clone, Serialize)] pub struct CardResult { pub met_flag: bool, pub stmts: Vec<StatementResult>, } #[derive(Debug, Clone, Serialize)] pub struct StatementResult { pub title: String, pub met_flag: bool, pub exp: Vec<ExpResult>, } pub struct Brick<T> { pub title: String, pub input: T, pub expcheck: Box<dyn Fn(T) -> ExpResult + 'static>, } impl<T> std::fmt::Debug for Brick<T> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self.title) } } impl<T> Brick<T> { pub fn report(self) -> ExpResult { (self.expcheck)(self.input) } } #[derive(Debug)] pub struct Statement<T> { pub title: String, pub contents: Vec<Brick<T>>, } impl<T> Statement<T> { pub fn report(self) -> StatementResult { let mut met_flag = false; let mut results = Vec::new(); for brick in self.contents { let out = brick.report(); if out.met_flag { met_flag = true; } results.push(out) } StatementResult { title: self.title, met_flag: met_flag, exp: results, } } } #[derive(Debug)] pub struct Card<T> { pub statements: Vec<Statement<T>>, } impl<T> Card<T> { pub fn report(self) -> CardResult { let mut met_flag = true; let mut results = Vec::new(); for statement in self.statements { let stmt = statement.report(); if !stmt.met_flag { met_flag = false; } results.push(stmt); } CardResult { stmts: results, met_flag: met_flag, } } } pub trait Config<T> { fn expression_function(&self) -> Box<dyn Fn(T) -> ExpResult + 'static>; fn name(&self) -> String; } impl<T> std::fmt::Debug for dyn Config<T> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name()) } }