tailcall_valid/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
mod append;
mod cause;
mod error;
mod valid;

pub use cause::*;
pub use error::*;
pub use valid::*;

/// Moral equivalent of TryFrom for validation purposes
pub trait ValidateFrom<T>: Sized {
    type Error;
    fn validate_from(a: T) -> Valid<Self, Self::Error>;
}

/// Moral equivalent of TryInto for validation purposes
pub trait ValidateInto<T> {
    type Error;
    fn validate_into(self) -> Valid<T, Self::Error>;
}

/// A blanket implementation for ValidateInto
impl<S, T: ValidateFrom<S>> ValidateInto<T> for S {
    type Error = T::Error;

    fn validate_into(self) -> Valid<T, Self::Error> {
        T::validate_from(self)
    }
}