danlehmann / arbitrary-int

A modern and lightweight implementation of arbitrary integers for Rust
MIT License
32 stars 13 forks source link

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

Open ariofrio opened 1 year ago

ariofrio commented 1 year ago

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:

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

hecatia-elegua commented 1 year ago

related to #36, a problem due to trait bounds