typeshift-derive 0.3.0

Proc-macro derive support for typeshift
Documentation

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:

  • Serialize
  • Deserialize
  • Validate
  • JsonSchema

Install

[dependencies]
typeshift = "0.3"

Quick start

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(())
}

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.
  • Unions are intentionally not supported.
  • #[derive(TypeShift)] is a legacy compatibility marker and does not generate impls.

More examples

  • cargo run -p typeshift --example basic
  • cargo run -p typeshift --example enum_tagged
  • cargo run -p typeshift --example generic_envelope
  • cargo run -p typeshift --example full_flow