Feature Request: Add attribute for types that don't implement Default
Heres a quick example of how it could look:
#[derive(EnumIter)]
pub enum AssetInfo {
Token {
#[strum(default=Addr::unchecked(""))]
contract_addr: Addr
},
NativeToken {
denom: String
},
}
This would be very useful when working with types from external crates, or when implementing Default doesn't otherwise make sense.
Hey @ewoolsey, there have been a few similiar requests, and I think this would be a very good fit for strum, but I haven't had time to implement it yet. If you're interested, I'd be happy to accept a PR, otherwise, I'll work on it when I have time.
I think I would err towards a design like the one serde uses #[serde(serialize_with = "path")] so that it feels familiar to people. Probably `#[strum(default_with = "path")] where path is the path to a function that accepts 0 arguments and returns a value of type T
@Peternator7 since posting this I’ve found an alternative solution (for my specific use case) with the clap Subcommand derive macro. My workload is pretty high the next few weeks so I’m not sure I’ll have time to contribute for a while, although I would like to get my hands dirty with some more involved proc macro projects. If you decide to pickup the torch on this let me know, I do think this would be a great addition to strum.
I will knock this out
I got a working proto type of this at the Variant Level + The Inner Variant Fields. Tests all pass and I didn't break anything. I plan on refactoring a little bit of the code, so Its easier to add Non-Derive / Non-Variant level macros (inner variant named fields), if its required in the future.