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

Refactor .new_unchecked() on enums into impl From<&str> #684

Open
Shnatsel opened this issue Apr 29, 2024 · 0 comments
Open

Refactor .new_unchecked() on enums into impl From<&str> #684

Shnatsel opened this issue Apr 29, 2024 · 0 comments

Comments

@Shnatsel
Copy link
Contributor

Shnatsel commented Apr 29, 2024

We have functions with signature pub(crate) fn new_unchecked<A: AsRef<str>>(value: A) -> Self on a number of enums, where the function converts any string to an enum variant and unrecognized strings go to the Unknown(String) variant.

It seems it would be more convenient and idiomatic to just impl From<&str> or impl FromStr instead of using a custom function. The generic A: AsRef<str> will be separately monomorphised for every type it is used with, increasing compilation time and binary size.

A potentially significant change is that trait implementations are automatically public, so there is no way to make them pub(crate). But exposing it publicly actually sounds like a good idea to me.

I originally brought this up in the review of #681

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

1 participant