Aldrin macros
The macros in this crate are not generally meant to be used directly, but through re-exports in other crates.
Procedural macros
Derive macros
- [
Serialize] - [
Deserialize] - [
Introspectable] - [
SerializeKey] - [
DeserializeKey] - [
KeyTypeOf] - [
AsSerializeArg]
All derive macros are re-exported in both aldrin and aldrin-core.
Attributes
All derive macros support various attributes and some apply to multiple macros.
Container attributes
crate
- Applies to: all derive macros
The attribute #[aldrin(crate = "...") can be used to override the path of the aldrin_core
crate. This is useful when aldrin_core is not a direct dependency, but only reexported
somewhere. The default value depends on from where the macro is invoked, it's either
::aldrin::core or ::aldrin_core.
{ser,de,intro,ser_key,de_key,key_ty}_bounds
Applies to:
ser_bounds: [Serialize], [AsSerializeArg]de_bounds: [Deserialize]intro_bounds: [Introspectable]ser_key_bounds: [SerializeKey]de_key_bounds: [DeserializeKey]key_ty_bounds: [KeyTypeOf]
These attributes specify the generic bounds added to where clauses The default is to add T: Trait bounds for each type parameter T and the respective trait.
The values of these attributes must be a string of comma-separated bounds, just like they would
appear in a where clause.
# use ;
schema
- Applies to:
Introspectable
Deriving Introspectable requires specifying a schema name. It is an error if this attribute is
missing.
# use Introspectable;
Field and variant attributes
id
- Applies to:
Serialize,DeserializeandIntrospectable
Use #[aldrin(id = ...)] to override the automatically defined id for a field or variant.
Default ids start at 0 for the first field or variant and then increment by 1 for each subsequent field or variant.
# use ;
# use ;
optional
- Applies to:
Serialize,DeserializeandIntrospectable
Use #[aldrin(optional)] to mark fields of a struct as optional. They must be of an Option<T>
type.
Optional fields are not serialized if None and are allowed to be missing when deserializing a
value.
# use ;
Both fields required_field_1 and required_field_2 will always be serialized and
deserialization will fail if either is missing. Serialization of optional_field is skipped if
it is None. If it's missing during deserialization, then it will be set to None.