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

From/TryFrom impls for generated types #224

Closed
ghost opened this issue Sep 21, 2020 · 3 comments
Closed

From/TryFrom impls for generated types #224

ghost opened this issue Sep 21, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Sep 21, 2020

It would be nice if the generated types had conversions to and from the underlying integer type, where the conversion to the underlying type calls bits, and the conversion from the underlying type calls eitherfrom_bits_truncate (if infallible) or from_bits (if fallible).

If there is interest in adding this I can make a PR.

@KodrAus
Copy link
Member

KodrAus commented Jul 19, 2021

This sounds good to me!

@KodrAus
Copy link
Member

KodrAus commented Oct 23, 2021

So we can’t actually add these From impls ourselves since a consumer might do it, but with #220 merged we could consider a #[bitflags_derive] crate that allowed deriving From and TryFrom.

@KodrAus
Copy link
Member

KodrAus commented Nov 25, 2021

Just coming back in through some triage. This isn't something we can or necessarily should add to bitflags itself, since users can write their own From impls, and there isn't a single universally correct implementation to choose. Whether you want to truncate or preserve additional bits is up to the author of the flags type to determine.

I'll go ahead and close this one now as something we won't be directly pursuing, but thanks for the suggestion!

@KodrAus KodrAus closed this as completed Nov 25, 2021
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