Skip to content

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

@Crypto-Spartan

Description

@Crypto-Spartan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions