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

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Serialize this value into the given Serde serializer. 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

Returns the argument unchanged.

Calls U::from(self).

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

Converts the given value to a String. 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.