Skip to main content

formars_core/
lib.rs

1//! `formars-core`: typed schema primitives with a dyn-safe erased view.
2//! Fluent builder schemas for validation, coercion and introspection — the
3//! kernel every other `formars*` crate builds on.
4//!
5//! A schema is a *value* you build, compose, and pass around:
6//!
7//! ```rust
8//! use formars_core::prelude::*;
9//!
10//! let s = string().trim().min(2).max(5);
11//! assert!(s.parse(&"ab".to_string()).is_ok());
12//! ```
13//!
14//! Every builder simultaneously implements the typed [`schema::Schema`] trait and the
15//! object-safe [`schema::DynSchema`] erased view from one internal representation, so
16//! both views always agree. Object schemas compose any builder family into
17//! struct-shaped validation over an ordered [`Value::Object`]:
18//!
19//! ```rust
20//! use formars_core::prelude::*;
21//!
22//! let user = object()
23//!     .field("name", string().min(1).label("Full name"))
24//!     .field("age", coerced::<u32>());
25//! ```
26//!
27//! [`Value::Object`]: crate::value::Value::Object
28
29/// String-to-type coercion schemas.
30pub mod coerce;
31/// Error model: accumulated, path-addressed issues.
32pub mod error;
33/// Struct↔schema contracts and value bridging for the opt-in `formars-derive` crate.
34pub mod form;
35/// Curated re-exports for typical users.
36pub mod prelude;
37/// Custom validation rules that compose identically to built-in checks.
38pub mod rule;
39/// The two validation views and their shared introspection types.
40pub mod schema;
41/// Primitive schema builders and their constructors.
42pub mod types;
43/// Pragmatic hand-rolled format validators (no regex dependency in v0).
44pub mod validators;
45/// Dependency-free dynamic value tree and its accessors.
46pub mod value;