Skip to main content

Crate rydantic

Crate rydantic 

Source
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::Value from a JSON literal.

Structs§

AsyncValidated
Immutable result of successful synchronous and asynchronous validation.
BorrowValidated
Context
Shared error collector used by generated code and custom JsonType implementations.
DynamicModel
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.
SchemaError
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.
ValidationError
Machine-readable validation failure. Raw input is deliberately not retained.
ValidationErrors

Enums§

Input
A JSON subtree that can retain references into the original input buffer.
PathSegment
A location in a nested input. Object keys and array indices remain distinct.
Stage
TypeKind
Value
Represents any valid JSON value.

Traits§

AsyncCheck
Asynchronous checks, executed after synchronous parsing and validation succeed. Implementations must leave the supplied context usable if the future is cancelled.
BorrowModel
Parsing API for a model containing references or Cow values.
BorrowType
Lifetime-aware counterpart of JsonType. Borrowing models use this extension point.
ExtraFields
Storage for #[model(extra)]. Keys are merged into the surrounding object.
JsonType
Extension point for JSON-compatible Rust types.
LengthType
Model
High-level model API generated by #[derive(Model)].
NumericType
ObjectType
Object shape information used by flattened fields, independent of ownership.
StringType
Marker traits make invalid attribute/type combinations fail during compilation.

Type Aliases§

BoxFuture

Attribute Macros§

capnp_models
Derive a complete Cap’n Proto protocol and its bindings from an inline model module.

Derive Macros§

Model
SqlModel
Derive SQL schema metadata, SQLx row decoding and validated CRUD operations.