Current atruct provides following 3 macros related to anonymous struct:
atruct!#[Return]#[withReturn]
atruct!
inspired by structx (that doesn't work now), atruct! macro enables to use variables of anonymous structs like
use atruct;
( examples/struct_of_various_values.rs )
-
atruct!supports nested structs. -
When atruct was v0.1 only literals are supported as values, BUT in v0.2 you can use (maybe) any type of values!
#[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] attribute enables such naming. You can write functions like
use Return;
// not supporting nest
( examples/return_struct.rs )
#[Return]doesn't support nested structs. So returned value is just like a tupple you can give any names to its fields.#[Return]automatically generates a struct named as "FunctionName" ( e.g. if function isget_abc, for example,GetAbc), but at the same time defines a type synonymReturn. So you DON't need to memorize the generated struct's name.
#[withReturn]
Actually, #[Return] itself is NOT available in impl block for a technical reason. #[withReturn] enables this:
use withReturn;
;
( examples/return_in_impl_block.rs )
- As you see, you don't need to
use atruct::Returnjust to write#[Return]inimplblocks. - Current
#[withReturn]generates structs in completely the same way as normal#[Return], meaning all functions using#[Return]have to have unique names to each others (This problem will be fixed in a few days).