subdef
This crate provides an attribute macro #[subdef] - it simplifies the creation of nested
structures, reduces boilerplate and helps keep logic in a single place.
[]
= "0.1"
It is a successor to nestify.
The biggest distinguishing feature is that items marked with #[subdef] can be
entirely formatted by rustfmt.
Usage
Apply #[subdef] to your type to be able to define inline types in individual fields
}],
friends: ,
status:
}
Expansion:
How it works
Fields on types marked with #[subdef] can have the type [Type; { Item }] where Type is the actual
type of the field, and Item is the struct or enum.
The Type can contain _, which infers to the name of the Item. In the above example:
- The
addressfield contains_, which infers to beAddress. - The
friendsfield contains_, which infers to beFriend, soVec<_>is inferred toVec<Friend>
You can apply #[subdef] to enums:
Inline types can contain fields that have inline types themselves:
]
}
}]
}
Admittedly, the syntax is a little strange, but that's a small price to pay for the
convenience of automatic formatting by rustfmt!
Propagate attributes
Give attributes to subdef(...), and they will be propagated recursively to all inline types
}],
application_config: ,
components: ,
}
}],
}
Expands to this, with fields omitted:
Fine-tune propagation
You can attach labels to each attribute:
These are the fine-tuning attributes that you can use:
#[subdef(skip(label1, label2))]to skip applying the attribute to the type#[subdef(skip_recursively(label1, label2))]to recursively skip applying the attribute to the type#[subdef(apply(label1, label2))]to apply the attribute, overriding any previous#[subdef(skip_recursively)]#[subdef(apply_recursively(label1, label2))]to recursively apply the attribute, overriding any previous#[subdef(skip_recursively)]
Example usage of these fine-tuning attributes:
}],
}
}],
shipping_details: ,
}
Expansion:
;