pub trait Format {
// Required methods
fn map_types(&self, types: &Types) -> Result<Cow<'_, Types>, FormatError>;
fn map_type(
&self,
types: &Types,
dt: &DataType,
) -> Result<Cow<'_, DataType>, FormatError>;
}Expand description
The format is used to inform Specta how the Serialize/Deserialization layer handles types.
This allows them to rewrite the collected types and encountered datatypes to apply format-specific macro attributes or behaviour.
Currently we have support for:
- serde via
specta-serde
Required Methods§
Sourcefn map_types(&self, types: &Types) -> Result<Cow<'_, Types>, FormatError>
fn map_types(&self, types: &Types) -> Result<Cow<'_, Types>, FormatError>
Apply a map function to the full Types collection.
Returns Cow::Borrowed when no changes are needed, or
Cow::Owned when the formatter produces a transformed collection.
Sourcefn map_type(
&self,
types: &Types,
dt: &DataType,
) -> Result<Cow<'_, DataType>, FormatError>
fn map_type( &self, types: &Types, dt: &DataType, ) -> Result<Cow<'_, DataType>, FormatError>
Map an individual DataType with access to the surrounding Types.
Returns Cow::Borrowed when no changes are needed, or
Cow::Owned when the formatter produces a transformed datatype.