You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to get your opinion on a few things I think we should consider before releasing 2.0, now that we have the chance:
Need to implement TryFrom<Int> for UInt and vice versa.
Reconsider how {UInt,Int}::from($primitive | $other_arbitrary_int) works. There's already an open issue mentioning this (u48::From<u64> should not be implemented, and so on; missing truncation function (like as) #37), but the current implementation is rather inconsistent when compared to primitive types. From is always implemented (which means we cannot implement TryFrom), even though using that implementation results in compiler errors if the source's bit width is larger than the target's. This gets inconsistent with signed integers: should UInt <-> Int conversions have the same limitation?
I think we should switch to only ever implementing TryFrom and return errors if the value doesn't fit. Lossless conversions are more versatile and more consistent with primitives.
Consider renaming Integer::from_(). Since this method does lossless conversions but From doesn't you can now have confusing situations like these:
u4::from(0_u16);// Error: bit width of 16 is greather than 4
u4::from_(0_u16);// This is fine
I think the method should be renamed to something more descriptive, perhaps something like new_lossless?
Integer::masked_new doesn't make sense for signed integers. Internally it sign-extends (much like an as cast) without doing any masking. In my opinion the method name should reflect the intent instead of the masking operation, maybe new_lossy?
I wanted to get your opinion on a few things I think we should consider before releasing 2.0, now that we have the chance:
TryFrom<Int> for UIntand vice versa.{UInt,Int}::from($primitive | $other_arbitrary_int)works. There's already an open issue mentioning this (u48::From<u64> should not be implemented, and so on; missing truncation function (likeas) #37), but the current implementation is rather inconsistent when compared to primitive types.Fromis always implemented (which means we cannot implementTryFrom), even though using that implementation results in compiler errors if the source's bit width is larger than the target's. This gets inconsistent with signed integers: shouldUInt<->Intconversions have the same limitation?I think we should switch to only ever implementing
TryFromand return errors if the value doesn't fit. Lossless conversions are more versatile and more consistent with primitives.Integer::from_(). Since this method does lossless conversions butFromdoesn't you can now have confusing situations like these:new_lossless?Integer::masked_newdoesn't make sense for signed integers. Internally it sign-extends (much like anascast) without doing any masking. In my opinion the method name should reflect the intent instead of the masking operation, maybenew_lossy?