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§
Provided Associated Constants§
Sourceconst BYTE_WIDTH: usize = _
const BYTE_WIDTH: usize = _
The byte level width of the integer(e.g. u32 is 4 bytes).
Required Associated Types§
Sourcetype UnsignedPair: IntegerType
type UnsignedPair: IntegerType
Self as an unsigned type with the same width.
Sourcetype SignedPair: IntegerType
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§
Sourcefn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>
fn try_from_bytes(input: &[u8], codec: Codec) -> Result<Self, DecodeError>
Sourcefn try_from_signed_bytes(
input: &[u8],
codec: Codec,
) -> Result<Self, DecodeError>
fn try_from_signed_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>
Sourcefn try_from_unsigned_bytes(
input: &[u8],
codec: Codec,
) -> Result<Self, DecodeError>
fn try_from_unsigned_bytes( input: &[u8], codec: Codec, ) -> Result<Self, DecodeError>
Sourcefn to_signed_bytes_be(&self) -> (impl AsRef<[u8]>, usize)
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.
Sourcefn to_unsigned_bytes_be(&self) -> (impl AsRef<[u8]>, usize)
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.
Sourcefn wrapping_unsigned_add(self, other: Self::UnsignedPair) -> Self
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.
Sourcefn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Whether the integer value is negative or not.
Sourcefn to_integer(self) -> Integer
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.