nest_struct
Nest struct and enum definitions with minimal syntax changes in Rust
Example
use nest_struct;
,
}
You can also overwrite inner struct name, by passing the name itself as macro instead of nest!
:
use nest_struct;
,
}
Or, you can open a block and define struct like normal Rust code for full flexibility:
use nest_struct;
},
}
/// doc comment for Author struct
use nest_struct;
// Define a struct with nested struct definitions all in one place
// with minimal syntax changes.
,
is_hidden: bool,
slot: u32,
},
>,
}
let body = get.unwrap.text.unwrap;
let api_response: APIResponse = from_str.unwrap;
assert_eq!;
// Access nested struct fields
assert_eq!;
For more examples, see the ./tests/cases
directory.
Features
- deep nesting (no theoretical limit).
- nest
struct
inside anotherstruct
. - nest
enum
inside anotherenum
. - nest
enum
inside astruct
and vice-versa. - inherit
derive
and other attribute macros from rootstruct
. - auto-generate inner
struct
names. - overwrite the auto-generated inner struct name.
Feature parity with native Rust code:
-
impl
block on innerstruct
s. - define
derive
and other attribute macros individually per innerstruct
. - define doc comments individually per inner
struct
. - useful compiler error messages.
- support generic types.
- support lifetimes.
Contributing
Contributions are welcome, please read CONTRIBUTING.md
to get started.
License
Licensed under MIT (twitter: @zibanpirate).