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§

§

Ok(T)

§

Err(Vec<E>)

Implementations§

source§

impl<T, E> Validated<T, E>
where T: HList,

source

pub fn is_ok(&self) -> bool

Returns true if this validation is Ok, false otherwise

Examples
use frunk::Validated;
use frunk::prelude::*;

let r1: Result<String, String> = Ok(String::from("hello"));
let v = r1.into_validated();
assert!(v.is_ok());
Run
source

pub fn is_err(&self) -> bool

Returns true if this validation is Err, false otherwise

Examples
use frunk::prelude::*;

let r1: Result<String, i32> = Err(32);
let v = r1.into_validated();
assert!(v.is_err());
Run
source

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,
            });
Run

Trait 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,

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)))
Run
§

type Output = Validated<<T as Add<HCons<T2, HNil>>>::Output, E>

The resulting type after applying the + operator.
source§

fn add(self, other: Result<T2, E>) -> Self::Output

Performs the + operation. Read more
source§

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)))
Run
§

type Output = Validated<<T as Add<T2>>::Output, E>

The resulting type after applying the + operator.
source§

fn add(self, other: Validated<T2, E>) -> Self::Output

Performs the + operation. Read more
source§

impl<T, E: Clone> Clone for Validated<T, E>
where T: HList + Clone,

source§

fn clone(&self) -> Validated<T, E>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, E: Debug> Debug for Validated<T, E>
where T: HList + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T, E: Hash> Hash for Validated<T, E>
where T: HList + Hash,

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T, E: Ord> Ord for Validated<T, E>
where T: HList + Ord,

source§

fn cmp(&self, other: &Validated<T, E>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T, E: PartialEq> PartialEq for Validated<T, E>
where T: HList + PartialEq,

source§

fn eq(&self, other: &Validated<T, E>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, E: PartialOrd> PartialOrd for Validated<T, E>
where T: HList + PartialOrd,

source§

fn partial_cmp(&self, other: &Validated<T, E>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, E: Eq> Eq for Validated<T, E>
where T: HList + Eq,

source§

impl<T, E> StructuralEq for Validated<T, E>
where T: HList,

source§

impl<T, E> StructuralPartialEq for Validated<T, E>
where T: HList,

Auto Trait Implementations§

§

impl<T, E> RefUnwindSafe for Validated<T, E>

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Choices> CoproductSubsetter<CNil, HNil> for Choices

§

type Remainder = Choices

source§

fn subset( self ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

source§

fn lift_into(self) -> U

Performs the indexed conversion.
source§

impl<Source> Sculptor<HNil, HNil> for Source

§

type Remainder = Source

source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.