Skip to main content

IntegerType

Trait IntegerType 

Source
pub trait IntegerType:
    Sized
    + Clone
    + Debug
    + Display
    + Default
    + TryInto<i64>
    + TryInto<i128>
    + TryInto<isize>
    + TryFrom<i64>
    + TryFrom<i128>
    + TryFrom<isize>
    + TryFrom<BigInt>
    + Into<BigInt>
    + ToBigInt
    + CheckedAdd
    + CheckedSub
    + PartialOrd
    + PartialEq
    + ToPrimitive {
    type UnsignedPair: IntegerType;
    type SignedPair: IntegerType;

    const WIDTH: u32;
    const ZERO: Self;
    const BYTE_WIDTH: usize = _;

    // Required methods
    fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>;
    fn try_from_signed_bytes(
        input: &[u8],
        codec: Codec,
    ) -> Result<Self, DecodeError>;
    fn try_from_unsigned_bytes(
        input: &[u8],
        codec: Codec,
    ) -> Result<Self, DecodeError>;
    fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize);
    fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize);
    fn wrapping_unsigned_add(self, other: Self::UnsignedPair) -> Self;
    fn is_negative(&self) -> bool;
    fn is_signed(&self) -> bool;
    fn to_integer(self) -> Integer;
}
Expand description

Represents a integer type in Rust that can be decoded or encoded into any ASN.1 codec.

Required Associated Constants§

Source

const WIDTH: u32

The bit level width of the integer (e.g. u32 is 32 bits).

Source

const ZERO: Self

Represents 0 in a given integer.

Provided Associated Constants§

Source

const BYTE_WIDTH: usize = _

The byte level width of the integer(e.g. u32 is 4 bytes).

Required Associated Types§

Source

type UnsignedPair: IntegerType

Self as an unsigned type with the same width.

Source

type SignedPair: IntegerType

Self as a signed type with one type size larger to prevent truncation, in case Self is unsigned. (e.g. u8 -> i16) Truncation would happen if unsigned type is converted to signed bytes with the same size.

Required Methods§

Source

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Attempts to convert the input data matching the given codec into Self.

§Errors

If the data doesn’t represent a valid integer in the given codec.

Source

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Attempts to convert the input data (assuming signed bytes) matching the given codec into Self.

§Errors

If the data doesn’t represent a valid integer in the given codec.

Source

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Attempts to convert the input data (assuming unsigned bytes) matching the given codec into Self.

§Errors

If the data doesn’t represent a valid integer in the given codec.

Source

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Returns a minimum number of signed Big Endian bytes needed to present the integer, byte count defined by usize.

Source

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Returns minimum number defined by usize of unsigned Big-endian bytes needed to present the the integer.

Source

fn wrapping_unsigned_add(self, other: Self::UnsignedPair) -> Self

Makes it possible to add unsigned integer to signed integer This is mainly used on UPER, in order to add unsigned offset into signed constrained minimum to get the resulting value as correct type. Casting will change the “value”, but same width makes the result ending to be correct.

Source

fn is_negative(&self) -> bool

Whether the integer value is negative or not.

Source

fn is_signed(&self) -> bool

Whether the integer type is signed or not.

Source

fn to_integer(self) -> Integer

Convert the underlying integer type into rasn ASN.1 Integer type.

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 IntegerType for i8

Source§

const WIDTH: u32 = i8::BITS

Source§

const ZERO: i8

Source§

type UnsignedPair = u8

Source§

type SignedPair = i8

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u8) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for i16

Source§

const WIDTH: u32 = i16::BITS

Source§

const ZERO: i16

Source§

type UnsignedPair = u16

Source§

type SignedPair = i16

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u16) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for i32

Source§

const WIDTH: u32 = i32::BITS

Source§

const ZERO: i32

Source§

type UnsignedPair = u32

Source§

type SignedPair = i32

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u32) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for i64

Source§

const WIDTH: u32 = i64::BITS

Source§

const ZERO: i64

Source§

type UnsignedPair = u64

Source§

type SignedPair = i64

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u64) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for i128

Source§

const WIDTH: u32 = i128::BITS

Source§

const ZERO: i128

Source§

type UnsignedPair = u128

Source§

type SignedPair = i128

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u128) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for isize

Source§

const WIDTH: u32 = isize::BITS

Source§

const ZERO: isize

Source§

type UnsignedPair = usize

Source§

type SignedPair = isize

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: usize) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for u8

Source§

const WIDTH: u32 = u8::BITS

Source§

const ZERO: u8

Source§

type UnsignedPair = u8

Source§

type SignedPair = i16

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u8) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for u16

Source§

const WIDTH: u32 = u16::BITS

Source§

const ZERO: u16

Source§

type UnsignedPair = u16

Source§

type SignedPair = i32

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u16) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for u32

Source§

const WIDTH: u32 = u32::BITS

Source§

const ZERO: u32

Source§

type UnsignedPair = u32

Source§

type SignedPair = i64

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u32) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for u64

Source§

const WIDTH: u32 = u64::BITS

Source§

const ZERO: u64

Source§

type UnsignedPair = u64

Source§

type SignedPair = i128

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u64) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for u128

Source§

const WIDTH: u32 = u128::BITS

Source§

const ZERO: u128

Source§

type UnsignedPair = u128

Source§

type SignedPair = i128

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: u128) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for usize

Source§

const WIDTH: u32 = usize::BITS

Source§

const ZERO: usize

Source§

type UnsignedPair = usize

Source§

type SignedPair = i128

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: usize) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Source§

impl IntegerType for BigInt

Source§

const WIDTH: u32 = u32::MAX

Source§

const ZERO: BigInt = BigInt::ZERO

Source§

type UnsignedPair = BigInt

Source§

type SignedPair = BigInt

Source§

fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>

Source§

fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>

Source§

fn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn wrapping_unsigned_add(self, other: Self) -> Self

Source§

fn is_negative(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn to_integer(self) -> Integer

Implementors§