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

Donwfall85/feature/enum impl #26

Closed
wants to merge 18 commits into from
Closed

Donwfall85/feature/enum impl #26

wants to merge 18 commits into from

Conversation

downfall85
Copy link

@downfall85 downfall85 commented Sep 4, 2021

Here is my attempt to implement enums in baseplug model. We can now write models like that:

baseplug::model! {
    #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
    enum MyEnum {
        A,
        B,
    }

    #[derive(Debug, Serialize, Deserialize)]
    struct MyModel {

        #[parameter(name = "param")]
        param: MyEnum
    }
}

Nearly all the job is done in the proc macro.

There is one thing that I would like to improve but I haven't any solution right now. We now need to import baseplug::Translatable and baseplug::Param in the plugin since the proc macro generates the implementation of the Translatable trait for the enum.

Let me know what do you think and how I can improve it.

@downfall85
Copy link
Author

I improved the implementation. It's cleaner and we don't need the imports anymore.

The Copy trait is now needed on the enum.

baseplug::model! {
    #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Copy)]
    enum MyEnum {
        A,
        B,
    }

    #[derive(Debug, Serialize, Deserialize)]
    struct MyModel {

        #[parameter(name = "param")]
        param: MyEnum
    }
}

@downfall85
Copy link
Author

With the work I did on the PR #28, I wonder if it wouldn't be wiser to avoid the blanket implementation

impl <P: Plugin, Model, T> Translatable <T, P, Model> for T
     where T: Copy + From <f32> + EnumModel, f32: From <T>

and instead make an implementation for each enum in the macro.. This would also get rid of the EnumModel trait.

@downfall85 downfall85 closed this by deleting the head repository Aug 5, 2023
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.

None yet

1 participant