result.rs (1232B)
1 use serde::{Deserialize, Serialize}; 2 3 #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] 4 pub struct ReplicaSchemaError<T> { 5 pub error: T, 6 } 7 8 #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] 9 pub struct ReplicaSchemaResult<T> { 10 pub result: T, 11 } 12 13 #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] 14 pub struct ReplicaSchemaResultList<T> { 15 pub results: Vec<T>, 16 } 17 18 #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] 19 pub struct ReplicaSchemaResultPass { 20 pub pass: bool, 21 } 22 23 impl<T> From<T> for ReplicaSchemaError<T> { 24 fn from(error: T) -> Self { 25 Self { error } 26 } 27 } 28 29 impl<T> ReplicaSchemaError<T> { 30 pub fn new(error: T) -> Self { 31 Self { error } 32 } 33 } 34 35 impl<T> ReplicaSchemaResult<T> { 36 pub fn new(result: T) -> Self { 37 Self { result } 38 } 39 } 40 41 impl<T> ReplicaSchemaResultList<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 ReplicaSchemaResultPass { 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 }