greyblake / kinded

Generate Rust enum variants without associated data
https://docs.rs/kinded/latest/kinded/
91 stars 2 forks source link

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

Open rster2002 opened 7 months ago

rster2002 commented 7 months ago

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.