Skip to main content

BigEndian

Struct BigEndian 

Source
pub struct BigEndian<T: EndianConvert>(/* private fields */);
Expand description

A transparent wrapper that stores an EndianConvert value in big-endian byte order.

BigEndian<T> is #[repr(transparent)] and implements PlainOldData, so it can be embedded directly in #[repr(C, packed)] raw structs used for zero-copy serialization.

Use new to construct from a native-endian value, and get to retrieve the native-endian value.

§Examples

use byteable::{BigEndian, ToByteArray};

let be = BigEndian::new(0x1234u16);
assert_eq!(be.get(), 0x1234u16);
// The internal bytes are stored in big-endian order:
assert_eq!(be.to_byte_array(), [0x12, 0x34]);

Implementations§

Source§

impl<T: EndianConvert> BigEndian<T>

Source

pub fn new(value: T) -> Self

Wraps value by converting it from native byte order to the target byte order.

Source

pub fn get(self) -> T

Retrieves the wrapped value, converting it from the stored byte order to native.

Trait Implementations§

Source§

impl<T: Clone + EndianConvert> Clone for BigEndian<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy + EndianConvert> Copy for BigEndian<T>

Source§

impl<T: Debug + EndianConvert> Debug for BigEndian<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: EndianConvert + Default> Default for BigEndian<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Eq + EndianConvert> Eq for BigEndian<T>

Source§

impl From<BigEndian<f32>> for f32

Source§

fn from(v: BigEndian<f32>) -> f32

Converts to this type from the input type.
Source§

impl From<BigEndian<f64>> for f64

Source§

fn from(v: BigEndian<f64>) -> f64

Converts to this type from the input type.
Source§

impl From<BigEndian<i16>> for i16

Source§

fn from(v: BigEndian<i16>) -> i16

Converts to this type from the input type.
Source§

impl From<BigEndian<i32>> for i32

Source§

fn from(v: BigEndian<i32>) -> i32

Converts to this type from the input type.
Source§

impl From<BigEndian<i64>> for i64

Source§

fn from(v: BigEndian<i64>) -> i64

Converts to this type from the input type.
Source§

impl From<BigEndian<i128>> for i128

Source§

fn from(v: BigEndian<i128>) -> i128

Converts to this type from the input type.
Source§

impl From<BigEndian<u16>> for u16

Source§

fn from(v: BigEndian<u16>) -> u16

Converts to this type from the input type.
Source§

impl From<BigEndian<u32>> for u32

Source§

fn from(v: BigEndian<u32>) -> u32

Converts to this type from the input type.
Source§

impl From<BigEndian<u64>> for u64

Source§

fn from(v: BigEndian<u64>) -> u64

Converts to this type from the input type.
Source§

impl From<BigEndian<u128>> for u128

Source§

fn from(v: BigEndian<u128>) -> u128

Converts to this type from the input type.
Source§

impl<T: EndianConvert> From<T> for BigEndian<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl FromByteArray for BigEndian<u16>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl FromByteArray for BigEndian<u32>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl FromByteArray for BigEndian<u64>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl FromByteArray for BigEndian<u128>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl FromByteArray for BigEndian<i16>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl FromByteArray for BigEndian<i32>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl FromByteArray for BigEndian<i64>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl FromByteArray for BigEndian<i128>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl FromByteArray for BigEndian<f32>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl FromByteArray for BigEndian<f64>

Source§

fn from_byte_array(byte_array: Self::ByteArray) -> Self

Deserialize a value from a fixed-size byte array. Infallible.
Source§

impl<T: EndianConvert> FromRawRepr for BigEndian<T>

Source§

fn from_raw(raw: Self::Raw) -> Self

Convert a raw representation into Self. Infallible.
Source§

impl<T: Hash + EndianConvert> Hash for BigEndian<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Ord + EndianConvert> Ord for BigEndian<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<T: PartialEq + EndianConvert> PartialEq for BigEndian<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialOrd + EndianConvert> PartialOrd for BigEndian<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: EndianConvert + PlainOldData> PlainOldData for BigEndian<T>

Source§

const BYTE_SIZE: usize

The number of bytes this type occupies in memory, equal to size_of::<Self>().
Source§

fn zeroed() -> Self

Returns a zero-initialized value of this type. Read more
Source§

fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ

Returns a mutable view of this value as a byte slice. Read more
Source§

fn as_bytes(&self) -> &[u8] ⓘ

Returns a read-only view of this value as a byte slice. Read more
Source§

impl<T: EndianConvert> RawRepr for BigEndian<T>

Source§

type Raw = BigEndian<T>

The PlainOldData type that Self serializes to.
Source§

fn to_raw(&self) -> Self::Raw

Convert this value to its raw representation for serialization.
Source§

impl ToByteArray for BigEndian<u16>

Source§

type ByteArray = [u8; 2]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl ToByteArray for BigEndian<u32>

Source§

type ByteArray = [u8; 4]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl ToByteArray for BigEndian<u64>

Source§

type ByteArray = [u8; 8]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl ToByteArray for BigEndian<u128>

Source§

type ByteArray = [u8; 16]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl ToByteArray for BigEndian<i16>

Source§

type ByteArray = [u8; 2]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl ToByteArray for BigEndian<i32>

Source§

type ByteArray = [u8; 4]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl ToByteArray for BigEndian<i64>

Source§

type ByteArray = [u8; 8]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl ToByteArray for BigEndian<i128>

Source§

type ByteArray = [u8; 16]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl ToByteArray for BigEndian<f32>

Source§

type ByteArray = [u8; 4]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl ToByteArray for BigEndian<f64>

Source§

type ByteArray = [u8; 8]

The fixed-size byte array type that this value serializes to (always [u8; N]).
Source§

fn to_byte_array(&self) -> Self::ByteArray

Serialize this value into a fixed-size byte array.
Source§

const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE

Compile-time byte size of the serialized form.
Source§

impl<T: EndianConvert> TryFromRawRepr for BigEndian<T>

Source§

fn try_from_raw(raw: Self::Raw) -> Result<Self, DecodeError>

Attempt to convert a raw representation into Self. Read more
Source§

impl WireFingerprint for BigEndian<u16>

Source§

impl WireFingerprint for BigEndian<u32>

Source§

impl WireFingerprint for BigEndian<u64>

Source§

impl WireFingerprint for BigEndian<u128>

Source§

impl WireFingerprint for BigEndian<i16>

Source§

impl WireFingerprint for BigEndian<i32>

Source§

impl WireFingerprint for BigEndian<i64>

Source§

impl WireFingerprint for BigEndian<i128>

Source§

impl WireFingerprint for BigEndian<f32>

Source§

impl WireFingerprint for BigEndian<f64>

Auto Trait Implementations§

§

impl<T> Forget for BigEndian<T>

§

impl<T> Freeze for BigEndian<T>
where T: Freeze,

§

impl<T> Move for BigEndian<T>

§

impl<T> RefUnwindSafe for BigEndian<T>
where T: RefUnwindSafe,

§

impl<T> Send for BigEndian<T>
where T: Send,

§

impl<T> Sync for BigEndian<T>
where T: Sync,

§

impl<T> Unpin for BigEndian<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for BigEndian<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for BigEndian<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> FixedReadable for T
where T: TryFromRawRepr,

Source§

fn read_fixed_from( reader: &mut (impl Read + ?Sized), ) -> Result<T, ReadableError>

Read exactly size_of::<Self::Raw>() bytes and decode them into Self. Read more
Source§

impl<T> FixedWritable for T
where T: RawRepr,

Source§

fn write_fixed_to( &self, writer: &mut (impl Write + ?Sized), ) -> Result<(), Error>

Write the fixed-size byte representation of self to writer. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Readable for T
where T: FixedReadable,

Source§

fn read_from(reader: &mut (impl Read + ?Sized)) -> Result<T, ReadableError>

Read a value from reader. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T> TryFromByteArray for T
where T: FromByteArray,

Source§

fn try_from_byte_array( byte_array: <T as ToByteArray>::ByteArray, ) -> Result<T, DecodeError>

Attempt to deserialize a value from a fixed-size byte array. Read more
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Writable for T
where T: FixedWritable,

Source§

fn write_to(&self, writer: &mut (impl Write + ?Sized)) -> Result<(), Error>

Write self to writer. Read more