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§

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

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

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§

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
The resulting type after applying the + operator.
Performs the + operation. Read more

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
The resulting type after applying the + operator.
Performs the + operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Extract a subset of the possible types in a coproduct (or get the remaining possibilities) Read more

Returns the argument unchanged.

Calls U::from(self).

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

Performs the indexed conversion.
Consumes the current HList and returns an HList with the requested shape. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.