types.rs (1047B)
1 use serde::Serialize; 2 3 #[derive(Clone, Debug, PartialEq, Eq, Serialize)] 4 pub struct IError<T> { 5 pub err: T, 6 } 7 8 #[derive(Clone, Debug, PartialEq, Eq, Serialize)] 9 pub struct IResult<T> { 10 pub result: T, 11 } 12 13 #[derive(Clone, Debug, PartialEq, Eq, Serialize)] 14 pub struct IResultList<T> { 15 pub results: Vec<T>, 16 } 17 18 #[derive(Clone, Debug, PartialEq, Eq, Serialize)] 19 pub struct IResultPass { 20 pub pass: bool, 21 } 22 23 impl<T> From<T> for IError<T> { 24 fn from(err: T) -> Self { 25 Self { err } 26 } 27 } 28 29 impl<T> IError<T> { 30 pub fn new(err: T) -> Self { 31 Self { err } 32 } 33 } 34 35 impl<T> IResult<T> { 36 pub fn new(result: T) -> Self { 37 Self { result } 38 } 39 } 40 41 impl<T> IResultList<T> { 42 pub fn new(results: Vec<T>) -> Self { 43 Self { results } 44 } 45 46 pub fn is_empty(&self) -> bool { 47 self.results.is_empty() 48 } 49 } 50 51 impl IResultPass { 52 pub fn new(pass: bool) -> Self { 53 Self { pass } 54 } 55 56 pub fn status_label(&self) -> &'static str { 57 if self.pass { "pass" } else { "fail" } 58 } 59 }