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

TryInto trait implementation #2

Closed
nazar-pc opened this issue Feb 3, 2020 · 2 comments
Closed

TryInto trait implementation #2

nazar-pc opened this issue Feb 3, 2020 · 2 comments

Comments

@nazar-pc
Copy link
Sponsor

nazar-pc commented Feb 3, 2020

::n() method is useful, but it would be even nicer to have standard implementation for TryInto trait in addition or instead of it.

@dtolnay
Copy link
Owner

dtolnay commented Feb 4, 2020

I would prefer to stick with just the associated function for now, with the TryFrom impl being handwritten if the author wants one. This crate is <100 lines though, so it would be easy to fork into a library that produces TryFrom.

There's also some talk of putting a TryFrom derive in the standard library for this use case: rust-lang/rfcs#2783.

@nazar-pc
Copy link
Sponsor Author

nazar-pc commented Feb 4, 2020

Subscribed to that issue. I just wanted to have a C-like enum that can deref to an integer and same way to use .try_into() for going backwards.

Boilerplate I had before was quote long and this library was the closest thing I found except it is missing actual deref and TryInto/TryFrom support, so code is still not as nice as it could have been.

@dtolnay dtolnay closed this as completed Apr 4, 2020
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

2 participants