pub trait Validator<T> {
type Target: PartialOrd<Self::Target> + PartialOrd<T> + ?Sized + 'static;
type Error;
// Provided methods
fn min() -> Option<&'static Self::Target> { ... }
fn max() -> Option<&'static Self::Target> { ... }
fn validate(_: &T) -> Result<(), Self::Error> { ... }
}Expand description
Validation strategy for GType.
A validator can:
- Define an optional minimum value via
Validator::min. - Define an optional maximum value via
Validator::max. - Perform arbitrary validation via
Validator::validate.
Validation is performed when constructing a GType using
GType::try_new.
§Note
Validator::Target is comparison target for checking bounds for T.
Its value must be comparable to itself and T.
Putting non-comparable value(e.g f32::NAN) might give error construction.
§Example
use core::convert::Infallible;
use g_type::{GType, Validator};
struct Percent;
impl Validator<u8> for Percent {
type Target = u8;
type Error = Infallible;
fn max() -> Option<&'static Self::Target> {
Some(&100)
}
}
let value = GType::<u8, Percent>::try_new(42);
assert!(value.is_ok());Required Associated Types§
Sourcetype Target: PartialOrd<Self::Target> + PartialOrd<T> + ?Sized + 'static
type Target: PartialOrd<Self::Target> + PartialOrd<T> + ?Sized + 'static
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".