pub trait NumberBytes: Sized {
const BYTES: usize;
// Required methods
fn to_ne_bytes(self) -> Vec<u8> ⓘ;
fn from_ne_bytes(bytes: &[u8]) -> FromBytesResult<Self>;
fn to_be_bytes(self) -> Vec<u8> ⓘ;
fn from_be_bytes(bytes: &[u8]) -> FromBytesResult<Self>;
fn to_le_bytes(self) -> Vec<u8> ⓘ;
fn from_le_bytes(bytes: &[u8]) -> FromBytesResult<Self>;
}
Required Associated Constants§
Required Methods§
Sourcefn to_ne_bytes(self) -> Vec<u8> ⓘ
fn to_ne_bytes(self) -> Vec<u8> ⓘ
Returns the memory representation of this integer as a byte array in native byte order.
Type-generic wrapper around [to_ne_bytes
] for inbuilt number types. See usize::to_ne_bytes
.
Size of the output vector shall always be the value of Self::BYTES
.
Sourcefn from_ne_bytes(bytes: &[u8]) -> FromBytesResult<Self>
fn from_ne_bytes(bytes: &[u8]) -> FromBytesResult<Self>
Creates a native endian value from its memory representation as a byte array in native endianness.
Type-generic wrapper around [from_ne_bytes
] for inbuilt number types. See usize::from_ne_bytes
.
Returns FromBytesError
if the size of the given byte-slice is incorrect.
Sourcefn to_be_bytes(self) -> Vec<u8> ⓘ
fn to_be_bytes(self) -> Vec<u8> ⓘ
Returns the memory representation of this integer as a byte array in big-endian (network) byte order.
Type-generic wrapper around [to_be_bytes
] for inbuilt number types. See usize::to_be_bytes
.
Size of the output vector shall always be the value of Self::BYTES
.
Sourcefn from_be_bytes(bytes: &[u8]) -> FromBytesResult<Self>
fn from_be_bytes(bytes: &[u8]) -> FromBytesResult<Self>
Creates a native endian integer value from its representation as a byte array in big endian.
Type-generic wrapper around [from_be_bytes
] for inbuilt number types. See usize::from_be_bytes
.
Returns FromBytesError
if the size of the given byte-slice is incorrect.
Sourcefn to_le_bytes(self) -> Vec<u8> ⓘ
fn to_le_bytes(self) -> Vec<u8> ⓘ
Returns the memory representation of this integer as a byte array in little-endian byte order.
Type-generic wrapper around [to_le_bytes
] for inbuilt number types. See usize::to_le_bytes
.
Size of the output vector shall always be the value of Self::BYTES
.
Sourcefn from_le_bytes(bytes: &[u8]) -> FromBytesResult<Self>
fn from_le_bytes(bytes: &[u8]) -> FromBytesResult<Self>
Creates a native endian integer value from its representation as a byte array in little endian.
Type-generic wrapper around [from_le_bytes
] for inbuilt number types. See usize::from_le_bytes
.
Returns FromBytesError
if the size of the given byte-slice is incorrect.
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.