pub enum Validated<T, E>where
T: HList,{
Ok(T),
Err(Vec<E>),
}
Expand description
A Validated is either an Ok holding an HList or an Err, holding a vector of collected errors.
Variants§
Implementations§
source§impl<T, E> Validated<T, E>where
T: HList,
impl<T, E> Validated<T, E>where T: HList,
sourcepub fn into_result(self) -> Result<T, Vec<E>>
pub fn into_result(self) -> Result<T, Vec<E>>
Turns this Validated into a Result.
If this Validated is Ok, it will become a Ok, holding an HList of all the accumulated results. Otherwise, it will become a Err with a list of all accumulated errors.
Examples
use frunk_core::hlist_pat;
use frunk::Validated;
use frunk::prelude::*;
#[derive(PartialEq, Eq, Debug)]
struct Person {
age: i32,
name: String,
}
fn get_name() -> Result<String, String> {
Ok("James".to_owned())
}
fn get_age() -> Result<i32, String> {
Ok(32)
}
let v = get_name().into_validated() + get_age();
let person = v.into_result()
.map(|hlist_pat!(name, age)| {
Person {
name,
age,
}
});
assert_eq!(person.unwrap(),
Person {
name: "James".to_owned(),
age: 32,
});
RunTrait Implementations§
source§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,
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,
Implements Add for the current Validated with a Result, returning a new Validated.
Examples
use frunk::Validated;
use frunk::prelude::*;
use frunk_core::hlist;
let r1: Result<String, String> = Ok(String::from("hello"));
let r2: Result<i32, String> = Ok(1);
let v = r1.into_validated() + r2;
assert_eq!(v, Validated::Ok(hlist!(String::from("hello"), 1)))
Runsource§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,
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,
Implements Add for the current Validated with another Validated, returning a new Validated.
Examples
use frunk::Validated;
use frunk::prelude::*;
use frunk_core::hlist;
let r1: Result<String, String> = Ok(String::from("hello"));
let r2: Result<i32, String> = 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)))
Runsource§impl<T, E: Ord> Ord for Validated<T, E>where
T: HList + Ord,
impl<T, E: Ord> Ord for Validated<T, E>where T: HList + Ord,
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<T, E: PartialEq> PartialEq for Validated<T, E>where
T: HList + PartialEq,
impl<T, E: PartialEq> PartialEq for Validated<T, E>where T: HList + PartialEq,
source§impl<T, E: PartialOrd> PartialOrd for Validated<T, E>where
T: HList + PartialOrd,
impl<T, E: PartialOrd> PartialOrd for Validated<T, E>where T: HList + PartialOrd,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T, E: Eq> Eq for Validated<T, E>where T: HList + Eq,
impl<T, E> StructuralEq for Validated<T, E>where T: HList,
impl<T, E> StructuralPartialEq for Validated<T, E>where T: HList,
Auto Trait Implementations§
impl<T, E> RefUnwindSafe for Validated<T, E>where E: RefUnwindSafe, T: RefUnwindSafe,
impl<T, E> Send for Validated<T, E>where E: Send, T: Send,
impl<T, E> Sync for Validated<T, E>where E: Sync, T: Sync,
impl<T, E> Unpin for Validated<T, E>where E: Unpin, T: Unpin,
impl<T, E> UnwindSafe for Validated<T, E>where E: UnwindSafe, T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more