Enum frust::validated::Validated
[−]
[src]
pub enum Validated<T, E> where
T: HList, { Ok(T), Err(Vec<E>), }
Variants
Ok(T)
Err(Vec<E>)
Methods
impl<T, E> Validated<T, E> where
T: HList,
[src]
T: HList,
fn is_ok(&self) -> bool
Returns true if this validation is Ok, false otherwise
let r1: Result<String, String> = Result::Ok(String::from("hello")); let v = r1.into_validated(); assert!(v.is_ok());
fn is_err(&self) -> bool
Returns true if this validation is Err, false otherwise
let r1: Result<String, i32> = Result::Err(32); let v = r1.into_validated(); assert!(v.is_err());
impl<T, E> Validated<T, E> where
T: HList,
[src]
T: HList,
fn into_result(self) -> Result<T, Vec<E>>
Turns this Validated into a Result.
If this Validated is Ok, it will become a Result::Ok, holding an HList of all the accumulated results. Otherwise, it will become a Result::Err with a list of all accumulated errors.
#[derive(PartialEq, Eq, Debug)] struct Person { age: i32, name: String, } fn get_name() -> Result<String, String> { Result::Ok("James".to_owned()) } fn get_age() -> Result<i32, String> { Result::Ok(32) } let v = get_name().into_validated() + get_age(); let person = v.into_result() .map(|hlist| { let (name,(age,_)) = hlist.into_tuple2(); Person { name: name, age: age, } }); assert_eq!(person, Result::Ok(Person { name: "James".to_owned(), age: 32, }));
Trait Implementations
impl<T: PartialEq, E: PartialEq> PartialEq for Validated<T, E> where
T: HList,
[src]
T: HList,
fn eq(&self, __arg_0: &Validated<T, E>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Validated<T, E>) -> bool
This method tests for !=
.
impl<T: Eq, E: Eq> Eq for Validated<T, E> where
T: HList,
[src]
T: HList,
impl<T: Debug, E: Debug> Debug for Validated<T, E> where
T: HList,
[src]
T: HList,
impl<T, E, T2> Add<Result<T2, E>> for Validated<T, E> where
T: HList + Add<HCons<T2, HNil>>,
<T as Add<HCons<T2, HNil>>>::Output: HList,
[src]
T: HList + Add<HCons<T2, HNil>>,
<T as Add<HCons<T2, HNil>>>::Output: HList,
Implements Add for the current Validated with a Result, returning a new Validated.
let r1: Result<String, String> = Result::Ok(String::from("hello")); let r2: Result<i32, String> = Result::Ok(1); let v = r1.into_validated() + r2; assert_eq!(v, Validated::Ok(hlist!(String::from("hello"), 1)))
type Output = Validated<<T as Add<HCons<T2, HNil>>>::Output, E>
The resulting type after applying the +
operator
fn add(self, other: Result<T2, E>) -> Self::Output
The method for the +
operator
impl<T, E, T2> Add<Validated<T2, E>> for Validated<T, E> where
T: HList + Add<T2>,
T2: HList,
<T as Add<T2>>::Output: HList,
[src]
T: HList + Add<T2>,
T2: HList,
<T as Add<T2>>::Output: HList,
Implements Add for the current Validated with another Validated, returning a new Validated.
let r1: Result<String, String> = Result::Ok(String::from("hello")); let r2: Result<i32, String> = Result::Ok(1); let v1 = r1.into_validated(); let v2 = r2.into_validated(); let v3 = v1 + v2; assert_eq!(v3, Validated::Ok(hlist!(String::from("hello"), 1)))