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

strum::EnumString deriving TryFrom<&str> means From<&str> cannot be implemented #255

Open
MingweiSamuel opened this issue Feb 26, 2023 · 3 comments

Comments

@MingweiSamuel
Copy link

In strum 0.23 the EnumString derive now implements TryFrom<&str> as well in #186

Problem with this is that TryFrom<&str> is automatically derived for &str: Into<MyEnum>: https://doc.rust-lang.org/stable/std/convert/trait.TryFrom.html#impl-TryFrom%3CU%3E-for-T

This means that after strum 0.22 it is no longer possible to implement From<&str> for MyEnum and/or Into<MyEnum> for &str. We would want to implement those especially if we have a #[strum(default)] field which would make parsing infallible (?).

Besides reverting, another fix would be to automatically implement From/Into if parsing is infallible

Same as #228 I imagine

@MingweiSamuel MingweiSamuel changed the title strum::EnumString deriving std::convert::TryFrom<&str> means From<&str> cannot be implemented strum::EnumString deriving TryFrom<&str> means From<&str> cannot be implemented Feb 26, 2023
@clouds56
Copy link

Is it possible to have strum generate a function try_from_str without implement TryFrom?
Since I'd like to handle some corner case myself.

@stjepangolemac
Copy link

Just came across this too. So there's no way to use EnumString for versions above 0.22?

@Peternator7
Copy link
Owner

This one-use case doesn't work, but it's not generally/totally broken no.

I would accept a PR to make the impl infallible if there's a default. it'd be a breaking change, but generally more accurate I'd say

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

4 participants