Skip to content

Implement From impls for NonZero, NonMax

Choose a tag to compare

@Techcable Techcable released this 31 Aug 02:40
dc1815a

Added

  • Add type aliases for NonMax and NonZero (i.e. NonZeroU32, NonMaxU32, etc.) (unqpkqks)
  • Add infallible From conversions for NonMax, NonZero (xutqswvn)
    • No failable conversions yet, as that would require defining a TryFromIntError type.
  • Add BITS associated constant to NonMax, NonZero (rslwssvw)
  • Add ONE, ZERO constants to NonMax and ONE constant to NonZero (mkyykwvx)
  • Require PrimitiveInt to implement int format traits (Binary, LowerHex, etc.) (kkmsmlmr)
    • This was always true of the underlying integer types, but not required by the trait.
  • Implement int format traits for NonZero, NonMax (Binary, LowerHex, etc.) (mrlslmyw)
    • Always implemented by delegating to underlying type, just like stdlib and the nonmax crate.

Changes

  • Delegate Debug impl for NonZero, NonMax to underlying type (qnlmtkkx)
    • Makes behavior consistent with stdlib and nonmax crate.
    • Previous behavior for NonZero was to format as newtype tuple struct (0 formats as NonZero(0)]
    • Previous behavior for NonMax was excessively verbose and exposed internal implementation details.
    • I don't consider this breaking since previous behavior was not guaranteed.
      The new behavior is guaranteed unless the stdlib changes it behavior.

Fixes

  • Fix Default impl for NonMax to return zero instead of one.