Number

Trait Number 

Source
pub trait Number: UnsignedInteger<UnderlyingType = Self::UnderlyingType> {
    type UnderlyingType: Integer + Debug + From<u8> + TryFrom<u16> + TryFrom<u32> + TryFrom<u64> + TryFrom<u128>;

    const BITS: usize = <Self as Integer>::BITS;
    const MIN: Self = <Self as Integer>::MIN;
    const MAX: Self = <Self as Integer>::MAX;

    // Provided methods
    fn new(value: <Self as Number>::UnderlyingType) -> Self { ... }
    fn try_new(
        value: <Self as Number>::UnderlyingType,
    ) -> Result<Self, TryNewError> { ... }
    fn value(self) -> <Self as Number>::UnderlyingType { ... }
    fn from_<T: Number>(value: T) -> Self { ... }
    fn masked_new<T: Number>(value: T) -> Self { ... }
    fn as_u8(&self) -> u8 { ... }
    fn as_u16(&self) -> u16 { ... }
    fn as_u32(&self) -> u32 { ... }
    fn as_u64(&self) -> u64 { ... }
    fn as_u128(&self) -> u128 { ... }
    fn as_usize(&self) -> usize { ... }
    fn as_<T: Number>(self) -> T { ... }
}
๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Expand description

Compatibility with arbitrary-int 1.x, which didnโ€™t support signed integers.

Going forward, use UnsignedInteger (to allow only unsigned integers) or Integer (to support either signed or unsigned).

It is suggested to import via use arbitrary_int::prelude::* as use arbitrary_int::* will pull in this trait as well, which causes clashes with Integer.

Provided Associated Constantsยง

Source

const BITS: usize = <Self as Integer>::BITS

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Number of bits that can fit in this type

Source

const MIN: Self = <Self as Integer>::MIN

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Minimum value that can be represented by this type

Source

const MAX: Self = <Self as Integer>::MAX

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Maximum value that can be represented by this type

Required Associated Typesยง

Source

type UnderlyingType: Integer + Debug + From<u8> + TryFrom<u16> + TryFrom<u32> + TryFrom<u64> + TryFrom<u128>

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Provided Methodsยง

Source

fn new(value: <Self as Number>::UnderlyingType) -> Self

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.

Source

fn try_new(value: <Self as Number>::UnderlyingType) -> Result<Self, TryNewError>

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Creates a number from the given value, return None if the value is too large

Source

fn value(self) -> <Self as Number>::UnderlyingType

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source

fn from_<T: Number>(value: T) -> Self

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.

Source

fn masked_new<T: Number>(value: T) -> Self

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.

Source

fn as_u8(&self) -> u8

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source

fn as_u16(&self) -> u16

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source

fn as_u32(&self) -> u32

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source

fn as_u64(&self) -> u64

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source

fn as_u128(&self) -> u128

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source

fn as_usize(&self) -> usize

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source

fn as_<T: Number>(self) -> T

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Dyn Compatibilityยง

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Typesยง

Sourceยง

impl Number for u8

Sourceยง

type UnderlyingType = u8

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Sourceยง

impl Number for u16

Sourceยง

type UnderlyingType = u16

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Sourceยง

impl Number for u32

Sourceยง

type UnderlyingType = u32

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Sourceยง

impl Number for u64

Sourceยง

type UnderlyingType = u64

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Sourceยง

impl Number for u128

Sourceยง

type UnderlyingType = u128

๐Ÿ‘ŽDeprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.

Implementorsยง

Sourceยง

impl<const BITS: usize> Number for UInt<u8, BITS>

Sourceยง

impl<const BITS: usize> Number for UInt<u16, BITS>

Sourceยง

impl<const BITS: usize> Number for UInt<u32, BITS>

Sourceยง

impl<const BITS: usize> Number for UInt<u64, BITS>

Sourceยง

impl<const BITS: usize> Number for UInt<u128, BITS>