1 stable release
1.0.0 | Oct 2, 2024 |
---|
#615 in Procedural macros
11KB
117 lines
OnionPack
Crate that will unpack your struct for layered architecture.
Usage
// This:
#[derive(onionpack::OnionPack)]
#[onion_derive(
all(Debug), // Describes what derives will have all structs
dto(PartialEq, Eq) // Describes what derives will have `UserDto`
// Can be appended wtith `scheme` and `entity` if you need derives for them.
)]
struct User {
name: String, // No `onion_dist` mean that this field will appear in all structs.
#[onion_dist(dto, entity)] // Describes where field will appear: `scheme` and/or `dto` and/or `entity`.
password_hash: String,
#[onion_dist(none)] // Doesn't appear in child structs.
hidden_value: i32,
}
// Generates this:
#[derive(Debug)]
pub struct UserScheme {
name: String,
}
#[derive(Debug, PartialEq, Eq)]
pub struct UserDto {
name: String,
password_hash: String,
}
#[derive(Debug)]
pub struct UserEntity {
name: String,
password_hash: String,
}
See UNPACK_EXAMPLE.md
or examples
for more examples.
Contributing
Wanna contribute?
- Are you a tech person? – You can find the
TODO
-list insrc/lib.rs
. - Are you an English speaker? – You can correct errors in any sentence in
README.md
,UNPACK_EXAMPLE.md
, etc.
License: MIT.
Dependencies
~215–650KB
~15K SLoC