Skip to content

Feat: ability to add inner attributes to generated kind enum - #16

Closed
rster2002 wants to merge 4 commits into
greyblake:masterfrom
rster2002:attrs-attribute
Closed

Feat: ability to add inner attributes to generated kind enum#16
rster2002 wants to merge 4 commits into
greyblake:masterfrom
rster2002:attrs-attribute

Conversation

@rster2002

@rster2002 rster2002 commented Mar 20, 2024

Copy link
Copy Markdown
Contributor

Hi,

I recently ran into the issue of needing the ability to add inner attributes to the generated kind enum for when using with Serde and Sqlx and opted to fork the lib and implement it. Not sure if this is something you want to add, but creating a PR for you to review.

It adds attrs attribute to the kinded attribute used in the derive macro:

use kinded::Kinded;
use serde::Serialize;
use serde_json::json;

#[derive(Kinded, Serialize)]
#[kinded(display = "snake_case", attrs(
    serde(rename_all = "snake_case"))
)]
enum Drink {
    VeryHotBlackTea,
    Milk { fat: f64 },
}

fn main() {
    let json_value = serde_json::to_value(&DrinkKind::VeryHotBlackTea);
    assert_eq!(json_value, json!("very_hot_black_tea"));
}

Anyway, let me know what you think and if this is something you would like to merge. Probably needs some more tests if you do want to merge this, but just let me know.

@greyblake greyblake mentioned this pull request Jan 29, 2026
@greyblake

Copy link
Copy Markdown
Owner

Thanks, I've rebased your changes and added some tests in #25.
It just got merged.

@greyblake greyblake closed this Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants