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

Implement TryFrom/TryInto #120

Closed
milesand opened this issue Dec 27, 2019 · 2 comments · Fixed by #123
Closed

Implement TryFrom/TryInto #120

milesand opened this issue Dec 27, 2019 · 2 comments · Fixed by #123

Comments

@milesand
Copy link
Contributor

Currently conversion between BigUInt, BigInt and primitives use dedicated traits ToBigInt, ToBigUInt and {To|From}Primitive, and not Try{From|Into} traits in std. While the functionality exists, this prevents using big integer types in a generic context that requires the latter. So, it would be preferable to implement them.

Some concerns:

  • It might be better to integrate ToBigInt and the like directly with Try{From|Into}. But I think that will cause breakage downstream, especially with {To|From}Primitive. Still, if there is a way to do this with out breaking things, this seems preferable.

  • Minimum supported rustc version. Since Try{From|Into} have been stable only since 1.34, I think naively implementing these would require bumping the rustc version number. Is there a way to avoid this? I'm not sure since I haven't dealt with minimum rustc versions before.

@cuviper
Copy link
Member

cuviper commented Jan 1, 2020

I wouldn't want any breaking changes to the existing traits, but we can add TryFrom separately for new enough toolchains. TryInto comes implicitly with TryFrom. I would also be more conservative with this to match core/std, e.g. not implementing from floating point types at all. (In the existing traits we convert from floating point with truncation.)

Minimum supported rustc version. Since Try{From|Into} have been stable only since 1.34, I think naively implementing these would require bumping the rustc version number. Is there a way to avoid this?

We can add a test in build.rs like ac.emit_path_cfg("std::convert::TryFrom", "has_try_from"), and then guard the actual implementations with #[cfg(has_try_from)].

@milesand
Copy link
Contributor Author

milesand commented Jan 2, 2020

Thanks, I'll work on a PR.

@bors bors bot closed this as completed in c076bb8 Mar 14, 2020
@bors bors bot closed this as completed in #123 Mar 14, 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

Successfully merging a pull request may close this issue.

2 participants