[][src]Enum frunk::validated::Validated

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]

pub fn is_ok(&self) -> bool[src]

Returns true if this validation is Ok, false otherwise

Examples

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

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

pub fn is_err(&self) -> bool[src]

Returns true if this validation is Err, false otherwise

Examples

use frunk::prelude::*;

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

pub fn into_result(self) -> Result<T, Vec<E>>[src]

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

#[macro_use] extern crate frunk;

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

#[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: Clone, E: Clone> Clone for Validated<T, E> where
    T: HList
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: PartialEq, E: PartialEq> PartialEq<Validated<T, E>> for Validated<T, E> where
    T: HList
[src]

impl<T: PartialOrd, E: PartialOrd> PartialOrd<Validated<T, E>> for Validated<T, E> where
    T: HList
[src]

impl<T: Ord, E: Ord> Ord for Validated<T, E> where
    T: HList
[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Returns max if self is greater than max, and min if self is less than min. Otherwise this will return self. Panics if min > max. Read more

impl<T: Eq, E: Eq> Eq for Validated<T, E> where
    T: HList
[src]

impl<T: Hash, E: Hash> Hash for Validated<T, E> where
    T: HList
[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

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]

Implements Add for the current Validated with a Result, returning a new Validated.

Examples

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

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 as Add<HCons<T2, HNil>>>::Output, E>

The resulting type after applying 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]

Implements Add for the current Validated with another Validated, returning a new Validated.

Examples

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

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

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

The resulting type after applying the + operator.

impl<T: Debug, E: Debug> Debug for Validated<T, E> where
    T: HList
[src]

Auto Trait Implementations

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

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<Choices> CoproductSubsetter for Choices[src]

type Remainder = Choices

impl<Source> Sculptor for Source[src]

type Remainder = Source

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