wapc/widl-codegen-js

add option to prevent derive(Default) for certain rust types

Closed this issue · 3 comments

I want to create an implementation of Default for my generated widl type that is not the standard rust Default implementation, but since src/generated.rs contains
#[derive(Debug, PartialEq, Deserialize, Serialize, Default, Clone)]
if I define my own impl Default for MyStruct in src/lib.rs, I get a compiler error that Default is already implemented.

My first thought was to suggest adding a cli flag to wapc generate such as --no-derive-default, to prevent Default from being generated, so I could create my own implementation in src/lib.rs.

But then I realized that if you have multiple struct types in the widl file, you might not want to implement Default for all of them, so a better implementation might be to add some lines to codegen.yml that give the name of the type and code-generation flags for that type, so if it's not overridden in codegen.yml, the Default would still be added to the generated derives list.

Do you think something like this is applicable to other languages or just Rust? I think widl supports the ability to add annotations that may be used by language-specific generators...not sure if that's in main yet though @pkedy

pkedy commented

This would be a config setting for the Visitor class. I'm going to transfer this issue for tracking to wapc/widl-codegen-js (the new repo).

This issue is no longer relevant for widl, and the feature is built into the smithy rust codegen.