pub struct Be<T>(pub T);Expand description
Big-endian wrapper: encodes and decodes T most significant byte first.
§Example
use wire_codec::{Be, Decode, Encode, ReadBuf, WriteBuf};
let mut out = [0u8; 4];
let mut buf = WriteBuf::new(&mut out);
Be(0xCAFE_u16).encode(&mut buf).unwrap();
Be(-2_i16).encode(&mut buf).unwrap();
assert_eq!(out, [0xCA, 0xFE, 0xFF, 0xFE]);
let mut r = ReadBuf::new(&out);
assert_eq!(Be::<u16>::decode(&mut r).unwrap().0, 0xCAFE);
assert_eq!(Be::<i16>::decode(&mut r).unwrap(), Be(-2));Tuple Fields§
§0: TTrait Implementations§
impl<T: Copy> Copy for Be<T>
impl<T: Eq> Eq for Be<T>
Source§impl<T: Ord> Ord for Be<T>
impl<T: Ord> Ord for Be<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Be<T>
impl<T: PartialOrd> PartialOrd for Be<T>
impl<T: PartialEq> StructuralPartialEq for Be<T>
Auto Trait Implementations§
impl<T> Freeze for Be<T>where
T: Freeze,
impl<T> RefUnwindSafe for Be<T>where
T: RefUnwindSafe,
impl<T> Send for Be<T>where
T: Send,
impl<T> Sync for Be<T>where
T: Sync,
impl<T> Unpin for Be<T>where
T: Unpin,
impl<T> UnsafeUnpin for Be<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Be<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more