Skip to main content

Crate typewire_derive

Crate typewire_derive 

Source
Expand description

Derive macro for the Typewire trait.

This crate provides #[derive(Typewire)], which generates platform-specific conversion methods and compile-time schema records from Rust types.

Most users should depend on typewire (which re-exports this macro) rather than depending on typewire-derive directly. See the typewire crate docs for supported targets and the full pipeline overview.

§Attribute reference

Attributes can be placed under #[serde(...)], #[diffable(...)], or #[typewire(...)]. The #[typewire(...)] namespace is a superset — when a type also derives Serialize/Deserialize, typewire reads #[serde] attributes too so you don’t need to duplicate them.

§Container attributes

AttributeEffect
rename_all = "..."Rename all fields (e.g. "camelCase", "snake_case")
rename_all_fields = "..."Rename fields in all enum variants
tag = "..."Internally-tagged enum
content = "..."Adjacent tagging (requires tag)
untaggedUntagged enum
transparentNewtype wrapper — delegates to inner type
defaultPer-field Default::default() fallback for missing fields
deny_unknown_fieldsError on unrecognized fields
from = "Type" / try_from = "Type"Proxy deserialization
into = "Type"Proxy serialization

§Variant attributes

AttributeEffect
rename = "..."Wire name for this variant
alias = "..."Additional accepted names (repeatable)
rename_all = "..."Rename fields within this variant
skipSkip entirely
skip_serializing / skip_deserializingSkip one direction
otherCatch-all for unknown variant names
untaggedUntagged within a tagged enum

§Field attributes

AttributeEffect
rename = "..."Wire name for this field
alias = "..."Additional accepted names (repeatable)
skipSkip entirely (field must impl Default)
default / default = "path"Use Default or custom fn when absent
flattenFlatten nested struct fields into parent
skip_serializing_if = "path"Conditionally omit on serialization
with = "serde_bytes"Use serde_bytes encoding
base64Base64 encode/decode Vec<u8> fields
displayUse Display/FromStr for conversion
lenientSkip invalid elements instead of failing

§Diffable attributes

AttributeEffect
atomicTreat as opaque for patching (no field-level diff)
visit_transparentGenerate patching code for transparent types

§Serde divergence

#[serde(default)] on a container uses per-field Default::default() fallbacks, not the container’s Default impl. This is intentional — the derive generates independent field fallbacks rather than constructing a default instance and overwriting present fields.

Derive Macros§

Typewire
Derive macro for the Typewire trait.