devela::num::niche

Macro impl_non_value

Source
macro_rules! impl_non_value {
    (
        // Defines a new signed non-value type. E.g.: impl_non_value![i 32]
        // would generate NonValueI32 and NonExtremeI32
        I $bits:literal) => { ... };
    (
        // Defines a new signed non-value type. E.g.: impl_non_value![u 32]
        // would generate NonValueU32 and NonExtremeU32
        U $bits:literal) => { ... };
    (
     /* private arms */
     @$XTR:ident, $doc:literal, $s:ident, $b:literal) => { ... };
    (
    // $name: the full name of the new type. E.g. NonValueI8.
    // $n0: the full name of the inner NonZero. E.g. NonZeroI8.
    // $ne: the full name of the new type. E.g. NonExtremeI8.
    //
    // $XTR:  the *extreme* value constant for this type. (MIN | MAX).
    // $doc:  the specific beginning of the documentation.
    // $IP:   the type of the corresponding integer primitive. E.g. i8
    // $s:    the sign identifier: i or u.
    // $b:    the bits of the type, from 8 to 128, or the `size` suffix.
    @$name:ident, $n0:ident, $ne:ident, $XTR:ident, $doc:literal, $IP:ty, $s:ident, $b:literal) => { ... };
}
Expand description

Implements a NonValue[I|U]B<V>.

  • I or U means a signed or unsigned type, respectively.
  • B represents the bit-size, from [8, 16, 32, 64, 128].
  • V is the prohibited value in the bit-sized range.

ยงExample

impl_non_value![I 8];

assert![NonValueI8::<3>::new(2).is_some()];
assert![NonValueI8::<3>::new(3).is_none()];

assert![NonExtremeI8::new(i8::MIN).is_none()];
assert![NonExtremeI8::new(i8::MAX).is_some()];
assert![NonExtremeI8::new(0).is_some()];

See for example: NonValueI8 and NonExtremeI8.