Validation and type constraint library. Declare domain types with invariants enforced at construction. Parse-dont-validate pattern as a first-class citizen. Zero-overhead wrappers with derive macros.
//! The shortest end-to-end use: a domain type that cannot hold an invalid value.
//!//! Run with: `cargo run --example quick_start`
usetype_lib::combinator::And;usetype_lib::rules::{LenRange, Trimmed};usetype_lib::Refined;/// A username: 3–16 characters, no leading or trailing whitespace.
typeUsername=Refined<String, And<Trimmed, LenRange<3, 16>>>;fnmain(){matchUsername::new("alice".to_owned()){Ok(user)=>println!("accepted: {user}"),Err(err)=>println!("rejected: {err}"),}// Each of these violates the rule and is rejected at construction.
for candidate in["ab"," spaced ","this-name-is-far-too-long"]{ifletErr(err)=Username::new(candidate.to_owned()){println!("rejected {candidate:?}: {err}");}}}