Expand description
typeshift facade crate.
This crate provides a Zod-like parse workflow using idiomatic Rust types.
Derive TypeShift on your struct or enum, then use:
parse_strfor parse + validateto_jsonfor serializationschema_jsonfor JSON Schema export
§Example
use typeshift::TypeShift;
#[derive(TypeShift)]
struct User {
#[validate(length(min = 3))]
name: String,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let user: User = typeshift::parse_str(r#"{"name":"Ada"}"#)?;
let json = typeshift::to_json(&user)?;
let schema = typeshift::schema_json::<User>();
assert_eq!(json, r#"{"name":"Ada"}"#);
assert_eq!(schema["type"], "object");
Ok(())
}Modules§
- schemars
- Core trait and runtime helpers.
- serde
- Core trait and runtime helpers.
- validator
- Core trait and runtime helpers.
Enums§
- Type
Shift Error - Core trait and runtime helpers.
Error returned by
parse_str.
Traits§
- Type
Shift - Core trait and runtime helpers. Marker trait for types that can be parsed, validated, and schematized.
Functions§
- parse_
str - Core trait and runtime helpers.
Parse JSON text into
Tand runvalidator::Validate. - schema_
json - Core trait and runtime helpers.
Generate a JSON Schema document for
Tasserde_json::Value. - to_json
- Core trait and runtime helpers. Serialize a typed value into a compact JSON string.
Derive Macros§
- Type
Shift - Derive macro that wires serde, validator, and schemars support.
Derives serde, validator, and schemars support required by
typeshift.