Skip to main content

type_lib/rules/
mod.rs

1//! Built-in validation rules.
2//!
3//! These are ready-to-use [`Validator`](crate::Validator) implementations for the
4//! most common invariants, grouped by what they constrain:
5//!
6//! - [length] — `NonEmpty`, `MinLen`, `MaxLen`, `LenRange`
7//! - [numeric] — `Positive`, `NonNegative`, `Negative`, `NonPositive`, `InRange`
8//! - [string] — `Ascii`, `Alphanumeric`, `Trimmed`
9//!
10//! Every built-in rule reports failures as [`ValidationError`](crate::ValidationError),
11//! so they share one error type and compose freely with the
12//! [combinators](crate::combinator).
13//!
14//! # Examples
15//!
16//! ```rust
17//! use type_lib::combinator::And;
18//! use type_lib::rules::{LenRange, Trimmed};
19//! use type_lib::Refined;
20//!
21//! // A display name: 1–32 characters, no surrounding whitespace.
22//! type DisplayName<'a> = Refined<&'a str, And<Trimmed, LenRange<1, 32>>>;
23//!
24//! assert!(DisplayName::new("Ada Lovelace").is_ok());
25//! assert!(DisplayName::new("  spaced  ").is_err());
26//! ```
27
28pub mod length;
29pub mod numeric;
30pub mod string;
31
32pub use length::{HasLength, LenRange, MaxLen, MinLen, NonEmpty};
33pub use numeric::{InRange, Negative, NonNegative, NonPositive, Positive};
34pub use string::{Alphanumeric, Ascii, Trimmed};