pub trait ToFromBytesEndian: Sized {
type AsBytesType: AsRef<[u8]>;
// Required methods
fn to_bytes_le(&self) -> Self::AsBytesType;
fn to_bytes_be(&self) -> Self::AsBytesType;
fn from_bytes_le(bytes: &[u8]) -> Option<Self>;
fn from_bytes_be(bytes: &[u8]) -> Option<Self>;
// Provided methods
fn byte_size() -> usize { ... }
fn to_bytes_ne(&self) -> Self::AsBytesType { ... }
fn from_bytes_ne(bytes: &[u8]) -> Option<Self> { ... }
fn to_bytes_endian(&self, endian: Option<Endian>) -> Self::AsBytesType { ... }
fn from_bytes_endian(bytes: &[u8], endian: Option<Endian>) -> Option<Self> { ... }
}Expand description
Trait for types that can be packed/unpack into/from bytes in either endian.
Required Associated Types§
type AsBytesType: AsRef<[u8]>
Required Methods§
fn to_bytes_le(&self) -> Self::AsBytesType
fn to_bytes_be(&self) -> Self::AsBytesType
fn from_bytes_le(bytes: &[u8]) -> Option<Self>
fn from_bytes_be(bytes: &[u8]) -> Option<Self>
Provided Methods§
fn byte_size() -> usize
fn to_bytes_ne(&self) -> Self::AsBytesType
fn from_bytes_ne(bytes: &[u8]) -> Option<Self>
fn to_bytes_endian(&self, endian: Option<Endian>) -> Self::AsBytesType
fn from_bytes_endian(bytes: &[u8], endian: Option<Endian>) -> Option<Self>
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 ToFromBytesEndian for bool
impl ToFromBytesEndian for bool
Source§fn from_bytes_ne(bytes: &[u8]) -> Option<Self>
fn from_bytes_ne(bytes: &[u8]) -> Option<Self>
§Example
use btle::bytes::ToFromBytesEndian;
assert_eq!(bool::from_bytes_ne(&[0]), Some(false));
assert_eq!(bool::from_bytes_ne(&[1]), Some(true));
assert_eq!(bool::from_bytes_ne(&[2]), None);