Enum frunk::validated::Validated
[−]
[src]
pub enum Validated<T, E> where T: HList { Ok(T), Err(Vec<E>), }
A Validated is either an Ok holding an HList or an Err, holding a vector of collected errors.
Variants
Ok(T)
Err(Vec<E>)
Methods
impl<T, E> Validated<T, E> where T: HList
[src]
fn is_ok(&self) -> bool
Returns true if this validation is Ok, false otherwise
Examples
let r1: Result<String, String> = Result::Ok(String::from("hello")); let v = r1.into_validated(); assert!(v.is_ok());Run
fn is_err(&self) -> bool
Returns true if this validation is Err, false otherwise
Examples
let r1: Result<String, i32> = Result::Err(32); let v = r1.into_validated(); assert!(v.is_err());Run
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.
Examples
#[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_pat!(name, age)| { Person { name: name, age: age, } }); assert_eq!(person.unwrap(), Person { name: "James".to_owned(), age: 32, });Run
Trait Implementations
impl<T: PartialEq, E: PartialEq> PartialEq for Validated<T, E> where T: HList
[src]
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: Debug, E: Debug> Debug for Validated<T, E> where T: HList
[src]
impl<T: Eq, E: Eq> Eq for Validated<T, E> where T: HList
[src]
impl<T: Clone, E: Clone> Clone for Validated<T, E> where T: HList
[src]
fn clone(&self) -> Validated<T, E>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: PartialOrd, E: PartialOrd> PartialOrd for Validated<T, E> where T: HList
[src]
fn partial_cmp(&self, __arg_0: &Validated<T, E>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Validated<T, E>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Validated<T, E>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Validated<T, E>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Validated<T, E>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T: Ord, E: Ord> Ord for Validated<T, E> where T: HList
[src]
fn cmp(&self, __arg_0: &Validated<T, E>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<T, E, T2> Add<Result<T2, E>> for Validated<T, E> where T: HList + Add<HCons<T2, HNil>>,
T::Output: HList
[src]
T::Output: HList
Implements Add for the current Validated with a Result, returning a new Validated.
Examples
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)))Run
type Output = Validated<T::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::Output: HList
[src]
T2: HList,
T::Output: HList
Implements Add for the current Validated with another Validated, returning a new Validated.
Examples
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)))Run