baseplug
                                
                                
                                
                                    baseplug copied to clipboard
                            
                            
                            
                        Donwfall85/feature/enum impl
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.
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
    }
}
                                    
                                    
                                    
                                
With the work I did on the PR https://github.com/wrl/baseplug/pull/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.