Skip to content

Things to consider before releasing 2.0 #75

@IvarWithoutBones

Description

@IvarWithoutBones

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?

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