Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rster2002
Copy link

@rster2002 rster2002 commented Mar 20, 2024

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.

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.

1 participant