Skip to content

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

@ariofrio

Description

@ariofrio

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions