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

u48::From<u64> should not be implemented, and so on; missing truncation function (like as) #37

Open
ariofrio opened this issue Sep 23, 2023 · 2 comments

Comments

@ariofrio
Copy link

The primitive unsigned integer types only implement Smaller::from(bigger) and Bigger::try_from(smaller). They do not implement Bigger::from(smaller), since that could cause truncation. Instead, as is used to convert without overflow checks and with truncation.

These Uint types should work the same way, to avoid accidentally truncating values. Instead, there should be the following options:

  • from(...) - only if the conversion is guaranteed to work
  • try_from(...).unwrap() - similar behavior to new() currently, panic on overflow
  • from_truncated() - or something like that, for an analogous version of primitive as

(Furthermore, it does not seem to be documented whether the Uint::From implementation truncates or panics on overflow.)

@ariofrio ariofrio changed the title u48::From<u64> should not be implemented, and so on u48::From<u64> should not be implemented, and so on; missing truncation function (like as) Sep 23, 2023
@hecatia-elegua
Copy link
Collaborator

related to #36, a problem due to trait bounds

@danlehmann
Copy link
Owner

#47 provides as_(), which provides to opposite of the from_truncated() that was requested in here

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