typeshift
typeshift provides a Zod-like parse workflow with idiomatic Rust types.
The struct or enum is the single source of truth. With one attribute, you get:
SerializeDeserializeValidateJsonSchema
Install
[]
= "0.5"
Quick start
use typeshift;
API
parse_str<T: TypeShift>(&str) -> Result<T, TypeShiftError>to_json<T: TypeShift>(&T) -> Result<String, serde_json::Error>schema_json<T: TypeShift>() -> serde_json::Value
Notes
#[typeshift]supports structs and enums, including generics.- Enum variant fields with
#[validate(...)]are validated duringparse_str. - Unions are intentionally not supported.
#[derive(TypeShift)]is a legacy compatibility marker and does not generate impls.- Current MSRV is Rust 1.81.
Validation to schema mapping
typeshift uses schemars and forwards compatible #[validate(...)] attributes
into generated JSON Schema. Common mappings include:
#[validate(email)]->format: "email"#[validate(url)]->format: "uri"#[validate(length(...))]->minLength/maxLength(orminItems/maxItems)#[validate(range(...))]->minimum/maximum#[validate(regex(path = ...))]->pattern#[validate(required)]onOption<T>-> schema treats field as requiredT
Some validators are runtime-only and not directly representable as JSON Schema
(for example custom, must_match, and nested behavior).
More examples
cargo run -p typeshift --example basiccargo run -p typeshift --example enum_taggedcargo run -p typeshift --example generic_envelopecargo run -p typeshift --example full_flow