Specta Serde
This applies Serde macro attributes on your types to the Specta generated types.
Using with Specta TypeScript
specta-serde exposes two format implementations for usage with any of the exporter crates, like specta-typescript:
specta_serde::format: unified shape for both serialize and deserialize.specta_serde::format_phases: split serialize/deserialize shapes.
format (unified shape)
Use format when serde behavior is symmetric and only a single TypeScript type is produced.
Note: This will error with certain Serde attributes like #[serde(rename(serialize = "a", deserialize = "b"))] as it's unclear what is correct.
use Types;
use Typescript;
let types = default.;
let output = default
.export
.unwrap;
assert!;
assert!;
You should always prefer format_phases where possible as it will generate a more accurate type.
format_phases (split by direction)
Use format_phases when the wire format can differ between serialization and deserialization. This may produce two different types, TypeName_Serialize and TypeName_Deserialize, to accurately represent both phases. It will produce TypeName as TypeName_Serialize | TypeName_Deserialize so the type can be used in a general format when needed.
This is common with directional serde metadata (serialize_with,
deserialize_with, from, into, try_from) or explicit
#[specta(type = specta_serde::Phased<SerializeTy, DeserializeTy>)] overrides.
use ;
use ;
use ;
use Typescript;
let types = default.;
let output = default
.export
.unwrap;
assert!;
assert!;
assert!;