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

Feature Request: Add attribute for types that don't implement Default #245

Open
ewoolsey opened this issue Oct 16, 2022 · 5 comments
Open

Comments

@ewoolsey
Copy link

ewoolsey commented Oct 16, 2022

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.

@Peternator7
Copy link
Owner

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.

@Peternator7
Copy link
Owner

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

@ewoolsey
Copy link
Author

@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.

@ericmcbride
Copy link
Contributor

I will knock this out

@ericmcbride
Copy link
Contributor

ericmcbride commented Feb 24, 2023

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.

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

No branches or pull requests

3 participants