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

Support for #[derive] inside of nested Enums #8

Open
Crypto-Spartan opened this issue Apr 28, 2024 · 1 comment
Open

Support for #[derive] inside of nested Enums #8

Crypto-Spartan opened this issue Apr 28, 2024 · 1 comment

Comments

@Crypto-Spartan
Copy link

Crypto-Spartan commented Apr 28, 2024

Firstly, thank you for your work on this crate! It's very helpful & useful. 😃

Currently, the following will not compile with Nestify:

nest! {
    #[derive(Debug, Clone)]*
    pub(crate) struct Item {
        pub(crate) id: u16,
        pub(crate) category:
            #[derive(Copy, PartialEq, Eq)]*
            pub(crate) enum ItemCategory {
                Item(
                    #[derive(Deserialize)]    // expected non-macro attribute, found attribute macro `derive` not a non-macro attribute
                    pub(crate) enum ItemType {
                        Regular,
                        Starter,
                        Glyph,
                    }
                ),
                Relic,
                Consumable
            },
        pub(crate) name: Box<str>,
    }
}

But, if I change it to this, it does work (which, as far as I can tell, should be the same thing):

nest! {
    #[derive(Debug, Clone)]*
    pub(crate) struct Item {
        pub(crate) id: u16,
        pub(crate) category:
            #[derive(Copy, PartialEq, Eq)]*
            pub(crate) enum ItemCategory {
                ItemType(ItemType),
                Relic,
                Consumable
            },
        pub(crate) name: Box<str>,
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
pub(crate) enum ItemType {
    Regular,
    Starter,
    Glyph,
}

This would work theoretically, but I have a custom deserialization already defined for ItemCategory, so it won't work for my use-case:

nest! {
    #[derive(Debug, Clone)]*
    pub(crate) struct Item {
        pub(crate) id: u16,
        pub(crate) category:
            #[derive(Copy, PartialEq, Eq, Deserialize)]*
            pub(crate) enum ItemCategory {
                Item(
                    pub(crate) enum ItemType {
                        Regular,
                        Starter,
                        Glyph,
                    }
                ),
                Relic,
                Consumable
            },
        pub(crate) name: Box<str>,
    }
}

I'm not sure if this is a bug or intended behavior, but it would be really great if it was possible to still use #[derive(Deserialize)] on an Enum inside of an Enum.

@snowfoxsh
Copy link
Owner

Thank you! I will look into this

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

No branches or pull requests

2 participants