Expand description
typeshift facade crate.
This crate provides a Zod-like parse workflow using idiomatic Rust types.
Use #[typeshift] on your struct or enum, then use:
parse_strfor parse + validateto_jsonfor serializationschema_jsonfor JSON Schema export
Many #[validate(...)] field attributes are reflected in schema output via
schemars (such as email, url, length, range, and regex).
§Example
use typeshift::typeshift;
#[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.
Attribute Macros§
- typeshift
- Attribute macro that adds serde, validator, and schemars derives.
Derive Macros§
- Type
Shift - Legacy compatibility derive.