Derive Macro typescript_type_def::TypeDef
source · [−]#[derive(TypeDef)]
{
// Attributes available to this derive:
#[type_def]
#[serde]
}
Expand description
A derive proc-macro for the TypeDef
trait.
This macro can be used on structs and enums which also derive
serde::Serialize
and/or
serde::Deserialize
,
and will generate a TypeDef
implementation which matches the shape
of the JSON produced by using serde_json
on
the target type. This macro will also read and adapt to #[serde(...)]
attributes on the target type’s definition.
This macro also reads the following attributes:
#[type_def(namespace = "x.y.z")]
on the struct/enum body puts the TypeScript type definition under a namespace ofx.y.z
. Note thatwrite_definition_file
will additionally place all type definitions under a root namespace.#[type_def(type_of = "T")]
on a struct or tuple field will use the Rust typeT
’s TypeScript definition instead of the field’s type.T
must be a valid Rust type which implementsTypeDef
and whose JSON format matches the JSON format of the field’s type. This attribute can be used to specify the type definition for a foreign type using your own type.
serde
attribute support
Legend:
- ✓ - full support
- ? - may support in the future
- ✗ - will not support