Trait IntegerEncoding

Source
pub trait IntegerEncoding
where Self: Sized,
{ type Bytes: ByteArray; // Required methods fn to_be_bytes(&self) -> Self::Bytes; fn to_le_bytes(&self) -> Self::Bytes; fn from_be_bytes_exact(bytes: &Self::Bytes) -> Option<Self>; fn from_le_bytes_exact(bytes: &Self::Bytes) -> Option<Self>; fn from_be_bytes_mod_order(bytes: &[u8]) -> Self; fn from_le_bytes_mod_order(bytes: &[u8]) -> Self; }
Expand description

Encodes an integer as bytes

Required Associated Types§

Source

type Bytes: ByteArray

Byte array that fits the whole encoded integer

Required Methods§

Source

fn to_be_bytes(&self) -> Self::Bytes

Encodes integer as bytes in big-endian byte order

Source

fn to_le_bytes(&self) -> Self::Bytes

Encodes integer as bytes in little-endian byte order

Source

fn from_be_bytes_exact(bytes: &Self::Bytes) -> Option<Self>

Decodes integer encoded as bytes in big-endian bytes order

Returns None if the bytes don’t correspond to a valid integer.

Source

fn from_le_bytes_exact(bytes: &Self::Bytes) -> Option<Self>

Decodes integer encoded as bytes in little-endian bytes order

Returns None if the bytes don’t correspond to a valid integer.

Source

fn from_be_bytes_mod_order(bytes: &[u8]) -> Self

Interprets bytes as big-endian encoding of an integer. Returns integer mod curve (prime) order.

Source

fn from_le_bytes_mod_order(bytes: &[u8]) -> Self

Interprets bytes as little-endian encoding of an integer. Returns integer mod curve (prime) order.

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.

Implementors§