Expand description
Built-in validation rules.
These are ready-to-use Validator implementations for the
most common invariants, grouped by what they constrain:
- length —
NonEmpty,MinLen,MaxLen,LenRange - numeric —
Positive,NonNegative,Negative,NonPositive,InRange - string —
Ascii,Alphanumeric,Trimmed
Every built-in rule reports failures as ValidationError,
so they share one error type and compose freely with the
combinators.
§Examples
use type_lib::combinator::And;
use type_lib::rules::{LenRange, Trimmed};
use type_lib::Refined;
// A display name: 1–32 characters, no surrounding whitespace.
type DisplayName<'a> = Refined<&'a str, And<Trimmed, LenRange<1, 32>>>;
assert!(DisplayName::new("Ada Lovelace").is_ok());
assert!(DisplayName::new(" spaced ").is_err());Re-exports§
pub use length::HasLength;pub use length::LenRange;pub use length::MaxLen;pub use length::MinLen;pub use length::NonEmpty;pub use numeric::InRange;pub use numeric::Negative;pub use numeric::NonNegative;pub use numeric::NonPositive;pub use numeric::Positive;pub use string::Alphanumeric;pub use string::Ascii;pub use string::Trimmed;