atruct
provides following 2 macros:
atruct!#[Return]
they are independent of each other.
atruct!
inspired by structx (that doesn't work now), enables to define anonymous structs like
use atruct;
( examples/define_struct.rs )
As you see, atruct supports nested structs.
NOTICE: Current atruct supports only literals as values. Additional supports are in progress...
#[Return]
We usually return more than 1 values from a function. In such situations, Rust supports only tupple as a way to bundle returned values. But it's sometimes a bit anoying: when we'd like to name freely to each field, not 0, 1, 2, ...
#[Return] enables this naming. You can write functions like
use Return;
// not supporting nest
( examples/return_struct.rs )
- Unlike
atruct!,#[Return]doesn't support nested structs (for a technical reason). So returned value is just like a tupple you can give any names to its fields. #[Return]automatically generates a struct named as "FunctionName" ( if function isget_abc, for example,GetAbc), But at the same time defines a type synonymReturn. So you DON't have to memorize or write the generated struct's name.