Skip to main content

Module prelude

Module prelude 

Source
Expand description

Common imports for working with type-lib.

Glob-import this module to bring the foundation types and the composition combinators into scope in one line. The built-in rules are intentionally left out to keep the namespace small; import the ones you need from type_lib::rules.

§Examples

use type_lib::prelude::*;
use type_lib::rules::{Ascii, NonEmpty};

// `Refined`, `Validator`, `ValidationError`, and `And`/`Or`/`Not` are all in
// scope from the prelude.
type Token<'a> = Refined<&'a str, And<NonEmpty, Ascii>>;

assert!(Token::new("abc123").is_ok());
assert!(Token::new("").is_err());

Re-exports§

pub use crate::combinator::And;
pub use crate::combinator::Not;
pub use crate::combinator::Or;

Structs§

Refined
A value of type T that is guaranteed to satisfy the validator V.
ValidationError
A lightweight validation failure with a machine-readable code and a human-readable message.

Traits§

Validator
A reusable validation rule applied to values of type T.