Skip to main content

TypeWriter

Derive Macro TypeWriter 

Source
#[derive(TypeWriter)]
{
    // Attributes available to this derive:
    #[sync_to]
    #[tw]
}
Expand description

Re-export the TypeWriter derive macro. Derive macro for typewriter type synchronization.

This macro generates type definitions in target languages from Rust structs and enums.

§Usage

use typebridge::TypeWriter;

#[derive(TypeWriter)]
#[sync_to(typescript, python)]
pub struct UserProfile {
    pub id: Uuid,
    pub email: String,
    pub age: Option<u32>,
}

§Errors

The macro will produce a compile error if:

  • #[sync_to(...)] is missing (required)
  • An unsupported language is specified
  • The type is a union (not supported)

§Output

On successful compilation, type files are generated:

  • TypeScript: generated/typescript/<type-name>.ts (+ .schema.ts for Zod)
  • Python: generated/python/<type_name>.py
  • Go: generated/go/<type_name>.go
  • And more for other target languages