onionpack

Crates.ioonionpack
lib.rsonionpack
version1.0.0
sourcesrc
created_at2024-10-02 11:24:35.590242
updated_at2024-10-02 11:24:35.590242
descriptionUnpack your structs into DTOs, Entities and Schemas.
homepage
repositoryhttps://github.com/h4-h/onionpack
max_upload_size
id1393948
size19,549
hash (h4-h)

documentation

README

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?

License: MIT.

Commit count: 12

cargo fmt