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

ToBigInt and ToBigUint should not return an error #13555

Closed
lifthrasiir opened this issue Apr 16, 2014 · 2 comments
Closed

ToBigInt and ToBigUint should not return an error #13555

lifthrasiir opened this issue Apr 16, 2014 · 2 comments

Comments

@lifthrasiir
Copy link
Contributor

It is a side effect of #9250, which added those traits as a special case of the FromPrimitive trait. This is rather strange, since the current ToBigInt implementors do not fail at all ( ToBigUint does fail, but only because they are implemented for signed integers as well).

Given that BigInt and BigUint already implements FromStr (that would correspond to impl<'a> ToBigInt for &'a str and so on), it would be better to make them implemented only for types that would definitely convertible to the big integers without an error. More precisely:

  • Make ToBigInt::to_bigint and ToBigUint::to_biguint return BigInt and BigUint respectively.
  • Remove implementations of ToBigUint for signed integers and BigInt.
  • Add a new into_biguint (since it's more efficient, and does not confuse users of ToBigUint) to BigInt, which returns Option<BigUint>. We may also have into_bigint to BigUint, at expense of symmetry (it becomes asymmetric since it should not return Option<BigInt>).
@rust-highfive
Copy link
Collaborator

This issue has been moved to the RFCs repo: rust-lang/rfcs#336

@rust-highfive
Copy link
Collaborator

This issue has been moved to the RFCs repo: rust-num/num#10

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

3 participants