Expand description
§parametrized crate

This Rust library provides a procedural macro attribute #[parametrized]
that automatically implements methods like Parametrized::param_iter()
, ParametrizedIntoIter::param_into_iter()
, ParametrizedIterMut::param_iter_mut()
, and ParametrizedMap::param_map()
for user-defined struct and enum types. The primary purpose of the library is to enable seamless traversal and transformation of complex data structures containing various nested collection types.
§Motivation
The parametrized library is particularly well-suited for handling complex data structures commonly found in compiler development and systems programming, such as Abstract Syntax Trees (ASTs) and Instruction Set Architectures (ISAs). These data structures often involve deeply nested collections and varying node types, making manual implementation of methods like iter, iter_mut, and map both tedious and error-prone.
§ISA example
#[parametrized(default, into_iter, map)]
enum Instruction<Operand: Ord> {
BinaryOp {
_op: String,
_src: Operand,
_dest: BTreeSet<Operand>,
},
LoadStore {
_op: String,
_address: Vec<(Operand, bool)>,
_value: Operand,
},
Branch {
_condition: String,
_target: String,
},
}
Traits§
- Parametrized
- Provide method to iterate about
PARAM
-th type parameter. For user-defined types, this trait is implemented byparametrized
macro withdefault
argument. - Parametrized
Into Iter - Provide
ParametrizedIntoIter::param_into_iter()
method to return iterator that consumes and iterates thePARAM
-th type parameter of given type. - Parametrized
Iter Mut - Provide
ParametrizedIterMut::param_iter_mut()
method to return mutable iterator, that iterates thePARAM
-th type parameter of given type. - Parametrized
Map - Provide
ParametrizedMap::param_map()
method to map values specified byPARAM
-th type parameter of given type.
Attribute Macros§
- parametrized
- Implement traits defined in
parametrized
crate, specifified by comma-separated arguments to this attribute macro#[parametrized(<args>)]
.