Expand description
Unified JSON models for Rust.
use rydantic::{Model, SchemaMode};
#[derive(Debug, Model)]
struct User {
#[model(trim, min_length = 3)]
name: String,
#[model(ge = 18, le = 120)]
age: u8,
}
let user = User::parse_json(r#"{"name":" Alice ","age":25}"#)?;
assert_eq!(user.name, "Alice");
assert!(User::json_schema(SchemaMode::Output).is_object());Re-exports§
pub use sql::SqlError;pub use sql::SqlModel;pub use capnp_support::CapnpSchema;pub use capnp_support::CapnpEnum;pub use capnp_support::CapnpModel;pub use schema::LocalRule;pub use schema::SchemaContext;pub use schema::SchemaMode;pub use schema::SchemaReport;pub use sqlx;pub use capnp;pub use chrono;pub use rust_decimal;
Modules§
- axum
- Axum extractors that preserve structured model errors and raw JSON input.
- capnp_
support - Native Cap’n Proto integration with automatic protocols and existing schemas. Model data maps directly to official readers and builders.
- rules
- schema
- sql
- SQLModel-style SQLite, PostgreSQL and MySQL persistence backed by SQLx and Tokio.
- stream
- Incremental JSON sequences, NDJSON and array visitors. Readers are synchronous.
Macros§
- json
- Construct a
serde_json::Valuefrom a JSON literal.
Structs§
- Async
Validated - Immutable result of successful synchronous and asynchronous validation.
- Borrow
Validated - Context
- Shared error collector used by generated code and custom
JsonTypeimplementations. - Dynamic
Model - Runtime JSON Schema validation. Compile once and reuse the validator.
- RawValue
- Reference to a range of bytes encompassing a single valid JSON value in the input data.
- Schema
Error - Validated
- Read-only access to a successfully checked model. No DerefMut or unchecked constructor. Interior-mutability types can weaken this guarantee; their JsonType implementation must document that behavior.
- Validation
Error - Machine-readable validation failure. Raw input is deliberately not retained.
- Validation
Errors
Enums§
- Input
- A JSON subtree that can retain references into the original input buffer.
- Path
Segment - A location in a nested input. Object keys and array indices remain distinct.
- Stage
- Type
Kind - Value
- Represents any valid JSON value.
Traits§
- Async
Check - Asynchronous checks, executed after synchronous parsing and validation succeed. Implementations must leave the supplied context usable if the future is cancelled.
- Borrow
Model - Parsing API for a model containing references or
Cowvalues. - Borrow
Type - Lifetime-aware counterpart of
JsonType. Borrowing models use this extension point. - Extra
Fields - Storage for
#[model(extra)]. Keys are merged into the surrounding object. - Json
Type - Extension point for JSON-compatible Rust types.
- Length
Type - Model
- High-level model API generated by
#[derive(Model)]. - Numeric
Type - Object
Type - Object shape information used by flattened fields, independent of ownership.
- String
Type - Marker traits make invalid attribute/type combinations fail during compilation.
Type Aliases§
Attribute Macros§
- capnp_
models - Derive a complete Cap’n Proto protocol and its bindings from an inline model module.