Function musli_zerocopy::endian::from_be
source · pub fn from_be<T: ZeroCopy>(value: T) -> T
Expand description
Convert the value T
from Big
to Native
endian.
This ignores types which has ZeroCopy::CAN_SWAP_BYTES
set to false
,
such as char
. Such values will simply pass through.
Swapping the bytes of a type which explicitly records its own byte order
like Ref<T>
is a no-op.
§Examples
use musli_zerocopy::{endian, ZeroCopy};
#[derive(Debug, PartialEq, ZeroCopy)]
#[repr(C)]
struct Struct {
c: char,
bits32: u32,
bits64: u64,
}
let st = endian::from_be(Struct {
c: 'a',
bits32: 0x10203040u32.to_be(),
bits64: 0x5060708090a0b0c0u64.to_be(),
});
assert_eq!(st, Struct {
c: 'a',
bits32: 0x10203040,
bits64: 0x5060708090a0b0c0,
});