Struct type_rules::Valid
source · [−]pub struct Valid<T: Validator>(_);
Expand description
Valid
is a wrapper for any type that implements Validator
it permit to ensure at compile time that the inner type as been
verified.
With the serde
feature, Valid can be serialized and deserialized
with validity check.
use type_rules::prelude::*;
#[derive(Validator)]
struct NewUser {
#[rule(MinMaxLength(3, 50))]
username: String,
#[rule(MinMaxLength(8, 100))]
password: String,
}
fn do_something(user: Valid<NewUser>) {
// No need to check if user is valid
}
let new_user = NewUser {
username: "example".to_string(),
password: "OPw$5%hJJ".to_string(),
};
do_something(Valid::new(new_user).unwrap());
Implementations
Trait Implementations
sourceimpl<'a, T: Validator + Deserialize<'a>> Deserialize<'a> for Valid<T>
Available on crate feature serde
only.
impl<'a, T: Validator + Deserialize<'a>> Deserialize<'a> for Valid<T>
Available on crate feature
serde
only.sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'a>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'a>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Valid<T> where
T: RefUnwindSafe,
impl<T> Send for Valid<T> where
T: Send,
impl<T> Sync for Valid<T> where
T: Sync,
impl<T> Unpin for Valid<T> where
T: Unpin,
impl<T> UnwindSafe for Valid<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more