ByteValued

Trait ByteValued 

pub unsafe trait ByteValued:
    Copy
    + Send
    + Sync {
    // Provided methods
    fn from_slice(data: &[u8]) -> Option<&Self> { ... }
    fn from_mut_slice(data: &mut [u8]) -> Option<&mut Self> { ... }
    fn as_slice(&self) -> &[u8]  { ... }
    fn as_mut_slice(&mut self) -> &mut [u8]  { ... }
    fn as_bytes(&mut self) -> VolatileSlice<'_> { ... }
    fn zeroed() -> Self { ... }
    fn write_all_to<W>(&self, writer: W) -> Result<(), Error>
       where W: Write { ... }
    fn read_exact_from<R>(reader: R) -> Result<Self, Error>
       where R: Read { ... }
}
Expand description

Types for which it is safe to initialize from raw data.

§Safety

A type T is ByteValued if and only if it can be initialized by reading its contents from a byte array. This is generally true for all plain-old-data structs. It is notably not true for any type that includes a reference. It is generally also not safe for non-packed structs, as compiler-inserted padding is considered uninitialized memory, and thus reads/writing it will cause undefined behavior.

Implementing this trait guarantees that it is safe to instantiate the struct with random data.

Provided Methods§

fn from_slice(data: &[u8]) -> Option<&Self>

Converts a slice of raw data into a reference of Self.

The value of data is not copied. Instead a reference is made from the given slice. The value of Self will depend on the representation of the type in memory, and may change in an unstable fashion.

This will return None if the length of data does not match the size of Self, or if the data is not aligned for the type of Self.

fn from_mut_slice(data: &mut [u8]) -> Option<&mut Self>

Converts a mutable slice of raw data into a mutable reference of Self.

Because Self is made from a reference to the mutable slice, mutations to the returned reference are immediately reflected in data. The value of the returned Self will depend on the representation of the type in memory, and may change in an unstable fashion.

This will return None if the length of data does not match the size of Self, or if the data is not aligned for the type of Self.

fn as_slice(&self) -> &[u8]

Converts a reference to self into a slice of bytes.

The value of self is not copied. Instead, the slice is made from a reference to self. The value of bytes in the returned slice will depend on the representation of the type in memory, and may change in an unstable fashion.

fn as_mut_slice(&mut self) -> &mut [u8]

Converts a mutable reference to self into a mutable slice of bytes.

Because the slice is made from a reference to self, mutations to the returned slice are immediately reflected in self. The value of bytes in the returned slice will depend on the representation of the type in memory, and may change in an unstable fashion.

fn as_bytes(&mut self) -> VolatileSlice<'_>

Converts a mutable reference to self into a VolatileSlice. This is useful because VolatileSlice provides a Bytes<usize> implementation.

fn zeroed() -> Self

Constructs a Self ewhose binary representation is set to all zeroes.

fn write_all_to<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

Writes this ByteValued’s byte representation to the given Write impl.

fn read_exact_from<R>(reader: R) -> Result<Self, Error>
where R: Read,

Constructs an instance of this ByteValued by reading from the given Read impl.

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§

§

impl ByteValued for i8

§

impl ByteValued for i16

§

impl ByteValued for i32

§

impl ByteValued for i64

§

impl ByteValued for i128

§

impl ByteValued for isize

§

impl ByteValued for u8

§

impl ByteValued for u16

§

impl ByteValued for u32

§

impl ByteValued for u64

§

impl ByteValued for u128

§

impl ByteValued for usize

§

impl ByteValued for VhostUserConfig

§

impl ByteValued for VhostUserEmpty

§

impl ByteValued for VhostUserGpuCursorPos

§

impl ByteValued for VhostUserGpuCursorUpdate

§

impl ByteValued for VhostUserGpuDMABUFScanout

§

impl ByteValued for VhostUserGpuDMABUFScanout2

§

impl ByteValued for VhostUserGpuEdidRequest

§

impl ByteValued for VhostUserGpuScanout

§

impl ByteValued for VhostUserGpuUpdate

§

impl ByteValued for VhostUserInflight

§

impl ByteValued for VhostUserLog

§

impl ByteValued for VhostUserMemory

§

impl ByteValued for VhostUserMemoryRegion

§

impl ByteValued for VhostUserSharedMsg

§

impl ByteValued for VhostUserSingleMemoryRegion

§

impl ByteValued for VhostUserTransferDeviceState

§

impl ByteValued for VhostUserU64

§

impl ByteValued for VhostUserVringAddr

§

impl ByteValued for VhostUserVringState

§

impl ByteValued for VirtioGpuCtrlHdr

§

impl ByteValued for VirtioGpuDisplayOne

§

impl ByteValued for VirtioGpuRect

§

impl ByteValued for VirtioGpuRespDisplayInfo

§

impl ByteValued for VirtioGpuRespGetEdid

§

impl ByteValued for [i8; 0]

§

impl ByteValued for [i8; 1]

§

impl ByteValued for [i8; 2]

§

impl ByteValued for [i8; 3]

§

impl ByteValued for [i8; 4]

§

impl ByteValued for [i8; 5]

§

impl ByteValued for [i8; 6]

§

impl ByteValued for [i8; 7]

§

impl ByteValued for [i8; 8]

§

impl ByteValued for [i8; 9]

§

impl ByteValued for [i8; 10]

§

impl ByteValued for [i8; 11]

§

impl ByteValued for [i8; 12]

§

impl ByteValued for [i8; 13]

§

impl ByteValued for [i8; 14]

§

impl ByteValued for [i8; 15]

§

impl ByteValued for [i8; 16]

§

impl ByteValued for [i8; 17]

§

impl ByteValued for [i8; 18]

§

impl ByteValued for [i8; 19]

§

impl ByteValued for [i8; 20]

§

impl ByteValued for [i8; 21]

§

impl ByteValued for [i8; 22]

§

impl ByteValued for [i8; 23]

§

impl ByteValued for [i8; 24]

§

impl ByteValued for [i8; 25]

§

impl ByteValued for [i8; 26]

§

impl ByteValued for [i8; 27]

§

impl ByteValued for [i8; 28]

§

impl ByteValued for [i8; 29]

§

impl ByteValued for [i8; 30]

§

impl ByteValued for [i8; 31]

§

impl ByteValued for [i8; 32]

§

impl ByteValued for [i16; 0]

§

impl ByteValued for [i16; 1]

§

impl ByteValued for [i16; 2]

§

impl ByteValued for [i16; 3]

§

impl ByteValued for [i16; 4]

§

impl ByteValued for [i16; 5]

§

impl ByteValued for [i16; 6]

§

impl ByteValued for [i16; 7]

§

impl ByteValued for [i16; 8]

§

impl ByteValued for [i16; 9]

§

impl ByteValued for [i16; 10]

§

impl ByteValued for [i16; 11]

§

impl ByteValued for [i16; 12]

§

impl ByteValued for [i16; 13]

§

impl ByteValued for [i16; 14]

§

impl ByteValued for [i16; 15]

§

impl ByteValued for [i16; 16]

§

impl ByteValued for [i16; 17]

§

impl ByteValued for [i16; 18]

§

impl ByteValued for [i16; 19]

§

impl ByteValued for [i16; 20]

§

impl ByteValued for [i16; 21]

§

impl ByteValued for [i16; 22]

§

impl ByteValued for [i16; 23]

§

impl ByteValued for [i16; 24]

§

impl ByteValued for [i16; 25]

§

impl ByteValued for [i16; 26]

§

impl ByteValued for [i16; 27]

§

impl ByteValued for [i16; 28]

§

impl ByteValued for [i16; 29]

§

impl ByteValued for [i16; 30]

§

impl ByteValued for [i16; 31]

§

impl ByteValued for [i16; 32]

§

impl ByteValued for [i32; 0]

§

impl ByteValued for [i32; 1]

§

impl ByteValued for [i32; 2]

§

impl ByteValued for [i32; 3]

§

impl ByteValued for [i32; 4]

§

impl ByteValued for [i32; 5]

§

impl ByteValued for [i32; 6]

§

impl ByteValued for [i32; 7]

§

impl ByteValued for [i32; 8]

§

impl ByteValued for [i32; 9]

§

impl ByteValued for [i32; 10]

§

impl ByteValued for [i32; 11]

§

impl ByteValued for [i32; 12]

§

impl ByteValued for [i32; 13]

§

impl ByteValued for [i32; 14]

§

impl ByteValued for [i32; 15]

§

impl ByteValued for [i32; 16]

§

impl ByteValued for [i32; 17]

§

impl ByteValued for [i32; 18]

§

impl ByteValued for [i32; 19]

§

impl ByteValued for [i32; 20]

§

impl ByteValued for [i32; 21]

§

impl ByteValued for [i32; 22]

§

impl ByteValued for [i32; 23]

§

impl ByteValued for [i32; 24]

§

impl ByteValued for [i32; 25]

§

impl ByteValued for [i32; 26]

§

impl ByteValued for [i32; 27]

§

impl ByteValued for [i32; 28]

§

impl ByteValued for [i32; 29]

§

impl ByteValued for [i32; 30]

§

impl ByteValued for [i32; 31]

§

impl ByteValued for [i32; 32]

§

impl ByteValued for [i64; 0]

§

impl ByteValued for [i64; 1]

§

impl ByteValued for [i64; 2]

§

impl ByteValued for [i64; 3]

§

impl ByteValued for [i64; 4]

§

impl ByteValued for [i64; 5]

§

impl ByteValued for [i64; 6]

§

impl ByteValued for [i64; 7]

§

impl ByteValued for [i64; 8]

§

impl ByteValued for [i64; 9]

§

impl ByteValued for [i64; 10]

§

impl ByteValued for [i64; 11]

§

impl ByteValued for [i64; 12]

§

impl ByteValued for [i64; 13]

§

impl ByteValued for [i64; 14]

§

impl ByteValued for [i64; 15]

§

impl ByteValued for [i64; 16]

§

impl ByteValued for [i64; 17]

§

impl ByteValued for [i64; 18]

§

impl ByteValued for [i64; 19]

§

impl ByteValued for [i64; 20]

§

impl ByteValued for [i64; 21]

§

impl ByteValued for [i64; 22]

§

impl ByteValued for [i64; 23]

§

impl ByteValued for [i64; 24]

§

impl ByteValued for [i64; 25]

§

impl ByteValued for [i64; 26]

§

impl ByteValued for [i64; 27]

§

impl ByteValued for [i64; 28]

§

impl ByteValued for [i64; 29]

§

impl ByteValued for [i64; 30]

§

impl ByteValued for [i64; 31]

§

impl ByteValued for [i64; 32]

§

impl ByteValued for [i128; 0]

§

impl ByteValued for [i128; 1]

§

impl ByteValued for [i128; 2]

§

impl ByteValued for [i128; 3]

§

impl ByteValued for [i128; 4]

§

impl ByteValued for [i128; 5]

§

impl ByteValued for [i128; 6]

§

impl ByteValued for [i128; 7]

§

impl ByteValued for [i128; 8]

§

impl ByteValued for [i128; 9]

§

impl ByteValued for [i128; 10]

§

impl ByteValued for [i128; 11]

§

impl ByteValued for [i128; 12]

§

impl ByteValued for [i128; 13]

§

impl ByteValued for [i128; 14]

§

impl ByteValued for [i128; 15]

§

impl ByteValued for [i128; 16]

§

impl ByteValued for [i128; 17]

§

impl ByteValued for [i128; 18]

§

impl ByteValued for [i128; 19]

§

impl ByteValued for [i128; 20]

§

impl ByteValued for [i128; 21]

§

impl ByteValued for [i128; 22]

§

impl ByteValued for [i128; 23]

§

impl ByteValued for [i128; 24]

§

impl ByteValued for [i128; 25]

§

impl ByteValued for [i128; 26]

§

impl ByteValued for [i128; 27]

§

impl ByteValued for [i128; 28]

§

impl ByteValued for [i128; 29]

§

impl ByteValued for [i128; 30]

§

impl ByteValued for [i128; 31]

§

impl ByteValued for [i128; 32]

§

impl ByteValued for [isize; 0]

§

impl ByteValued for [isize; 1]

§

impl ByteValued for [isize; 2]

§

impl ByteValued for [isize; 3]

§

impl ByteValued for [isize; 4]

§

impl ByteValued for [isize; 5]

§

impl ByteValued for [isize; 6]

§

impl ByteValued for [isize; 7]

§

impl ByteValued for [isize; 8]

§

impl ByteValued for [isize; 9]

§

impl ByteValued for [isize; 10]

§

impl ByteValued for [isize; 11]

§

impl ByteValued for [isize; 12]

§

impl ByteValued for [isize; 13]

§

impl ByteValued for [isize; 14]

§

impl ByteValued for [isize; 15]

§

impl ByteValued for [isize; 16]

§

impl ByteValued for [isize; 17]

§

impl ByteValued for [isize; 18]

§

impl ByteValued for [isize; 19]

§

impl ByteValued for [isize; 20]

§

impl ByteValued for [isize; 21]

§

impl ByteValued for [isize; 22]

§

impl ByteValued for [isize; 23]

§

impl ByteValued for [isize; 24]

§

impl ByteValued for [isize; 25]

§

impl ByteValued for [isize; 26]

§

impl ByteValued for [isize; 27]

§

impl ByteValued for [isize; 28]

§

impl ByteValued for [isize; 29]

§

impl ByteValued for [isize; 30]

§

impl ByteValued for [isize; 31]

§

impl ByteValued for [isize; 32]

§

impl ByteValued for [u8; 0]

§

impl ByteValued for [u8; 1]

§

impl ByteValued for [u8; 2]

§

impl ByteValued for [u8; 3]

§

impl ByteValued for [u8; 4]

§

impl ByteValued for [u8; 5]

§

impl ByteValued for [u8; 6]

§

impl ByteValued for [u8; 7]

§

impl ByteValued for [u8; 8]

§

impl ByteValued for [u8; 9]

§

impl ByteValued for [u8; 10]

§

impl ByteValued for [u8; 11]

§

impl ByteValued for [u8; 12]

§

impl ByteValued for [u8; 13]

§

impl ByteValued for [u8; 14]

§

impl ByteValued for [u8; 15]

§

impl ByteValued for [u8; 16]

§

impl ByteValued for [u8; 17]

§

impl ByteValued for [u8; 18]

§

impl ByteValued for [u8; 19]

§

impl ByteValued for [u8; 20]

§

impl ByteValued for [u8; 21]

§

impl ByteValued for [u8; 22]

§

impl ByteValued for [u8; 23]

§

impl ByteValued for [u8; 24]

§

impl ByteValued for [u8; 25]

§

impl ByteValued for [u8; 26]

§

impl ByteValued for [u8; 27]

§

impl ByteValued for [u8; 28]

§

impl ByteValued for [u8; 29]

§

impl ByteValued for [u8; 30]

§

impl ByteValued for [u8; 31]

§

impl ByteValued for [u8; 32]

§

impl ByteValued for [u16; 0]

§

impl ByteValued for [u16; 1]

§

impl ByteValued for [u16; 2]

§

impl ByteValued for [u16; 3]

§

impl ByteValued for [u16; 4]

§

impl ByteValued for [u16; 5]

§

impl ByteValued for [u16; 6]

§

impl ByteValued for [u16; 7]

§

impl ByteValued for [u16; 8]

§

impl ByteValued for [u16; 9]

§

impl ByteValued for [u16; 10]

§

impl ByteValued for [u16; 11]

§

impl ByteValued for [u16; 12]

§

impl ByteValued for [u16; 13]

§

impl ByteValued for [u16; 14]

§

impl ByteValued for [u16; 15]

§

impl ByteValued for [u16; 16]

§

impl ByteValued for [u16; 17]

§

impl ByteValued for [u16; 18]

§

impl ByteValued for [u16; 19]

§

impl ByteValued for [u16; 20]

§

impl ByteValued for [u16; 21]

§

impl ByteValued for [u16; 22]

§

impl ByteValued for [u16; 23]

§

impl ByteValued for [u16; 24]

§

impl ByteValued for [u16; 25]

§

impl ByteValued for [u16; 26]

§

impl ByteValued for [u16; 27]

§

impl ByteValued for [u16; 28]

§

impl ByteValued for [u16; 29]

§

impl ByteValued for [u16; 30]

§

impl ByteValued for [u16; 31]

§

impl ByteValued for [u16; 32]

§

impl ByteValued for [u32; 0]

§

impl ByteValued for [u32; 1]

§

impl ByteValued for [u32; 2]

§

impl ByteValued for [u32; 3]

§

impl ByteValued for [u32; 4]

§

impl ByteValued for [u32; 5]

§

impl ByteValued for [u32; 6]

§

impl ByteValued for [u32; 7]

§

impl ByteValued for [u32; 8]

§

impl ByteValued for [u32; 9]

§

impl ByteValued for [u32; 10]

§

impl ByteValued for [u32; 11]

§

impl ByteValued for [u32; 12]

§

impl ByteValued for [u32; 13]

§

impl ByteValued for [u32; 14]

§

impl ByteValued for [u32; 15]

§

impl ByteValued for [u32; 16]

§

impl ByteValued for [u32; 17]

§

impl ByteValued for [u32; 18]

§

impl ByteValued for [u32; 19]

§

impl ByteValued for [u32; 20]

§

impl ByteValued for [u32; 21]

§

impl ByteValued for [u32; 22]

§

impl ByteValued for [u32; 23]

§

impl ByteValued for [u32; 24]

§

impl ByteValued for [u32; 25]

§

impl ByteValued for [u32; 26]

§

impl ByteValued for [u32; 27]

§

impl ByteValued for [u32; 28]

§

impl ByteValued for [u32; 29]

§

impl ByteValued for [u32; 30]

§

impl ByteValued for [u32; 31]

§

impl ByteValued for [u32; 32]

§

impl ByteValued for [u64; 0]

§

impl ByteValued for [u64; 1]

§

impl ByteValued for [u64; 2]

§

impl ByteValued for [u64; 3]

§

impl ByteValued for [u64; 4]

§

impl ByteValued for [u64; 5]

§

impl ByteValued for [u64; 6]

§

impl ByteValued for [u64; 7]

§

impl ByteValued for [u64; 8]

§

impl ByteValued for [u64; 9]

§

impl ByteValued for [u64; 10]

§

impl ByteValued for [u64; 11]

§

impl ByteValued for [u64; 12]

§

impl ByteValued for [u64; 13]

§

impl ByteValued for [u64; 14]

§

impl ByteValued for [u64; 15]

§

impl ByteValued for [u64; 16]

§

impl ByteValued for [u64; 17]

§

impl ByteValued for [u64; 18]

§

impl ByteValued for [u64; 19]

§

impl ByteValued for [u64; 20]

§

impl ByteValued for [u64; 21]

§

impl ByteValued for [u64; 22]

§

impl ByteValued for [u64; 23]

§

impl ByteValued for [u64; 24]

§

impl ByteValued for [u64; 25]

§

impl ByteValued for [u64; 26]

§

impl ByteValued for [u64; 27]

§

impl ByteValued for [u64; 28]

§

impl ByteValued for [u64; 29]

§

impl ByteValued for [u64; 30]

§

impl ByteValued for [u64; 31]

§

impl ByteValued for [u64; 32]

§

impl ByteValued for [u128; 0]

§

impl ByteValued for [u128; 1]

§

impl ByteValued for [u128; 2]

§

impl ByteValued for [u128; 3]

§

impl ByteValued for [u128; 4]

§

impl ByteValued for [u128; 5]

§

impl ByteValued for [u128; 6]

§

impl ByteValued for [u128; 7]

§

impl ByteValued for [u128; 8]

§

impl ByteValued for [u128; 9]

§

impl ByteValued for [u128; 10]

§

impl ByteValued for [u128; 11]

§

impl ByteValued for [u128; 12]

§

impl ByteValued for [u128; 13]

§

impl ByteValued for [u128; 14]

§

impl ByteValued for [u128; 15]

§

impl ByteValued for [u128; 16]

§

impl ByteValued for [u128; 17]

§

impl ByteValued for [u128; 18]

§

impl ByteValued for [u128; 19]

§

impl ByteValued for [u128; 20]

§

impl ByteValued for [u128; 21]

§

impl ByteValued for [u128; 22]

§

impl ByteValued for [u128; 23]

§

impl ByteValued for [u128; 24]

§

impl ByteValued for [u128; 25]

§

impl ByteValued for [u128; 26]

§

impl ByteValued for [u128; 27]

§

impl ByteValued for [u128; 28]

§

impl ByteValued for [u128; 29]

§

impl ByteValued for [u128; 30]

§

impl ByteValued for [u128; 31]

§

impl ByteValued for [u128; 32]

§

impl ByteValued for [usize; 0]

§

impl ByteValued for [usize; 1]

§

impl ByteValued for [usize; 2]

§

impl ByteValued for [usize; 3]

§

impl ByteValued for [usize; 4]

§

impl ByteValued for [usize; 5]

§

impl ByteValued for [usize; 6]

§

impl ByteValued for [usize; 7]

§

impl ByteValued for [usize; 8]

§

impl ByteValued for [usize; 9]

§

impl ByteValued for [usize; 10]

§

impl ByteValued for [usize; 11]

§

impl ByteValued for [usize; 12]

§

impl ByteValued for [usize; 13]

§

impl ByteValued for [usize; 14]

§

impl ByteValued for [usize; 15]

§

impl ByteValued for [usize; 16]

§

impl ByteValued for [usize; 17]

§

impl ByteValued for [usize; 18]

§

impl ByteValued for [usize; 19]

§

impl ByteValued for [usize; 20]

§

impl ByteValued for [usize; 21]

§

impl ByteValued for [usize; 22]

§

impl ByteValued for [usize; 23]

§

impl ByteValued for [usize; 24]

§

impl ByteValued for [usize; 25]

§

impl ByteValued for [usize; 26]

§

impl ByteValued for [usize; 27]

§

impl ByteValued for [usize; 28]

§

impl ByteValued for [usize; 29]

§

impl ByteValued for [usize; 30]

§

impl ByteValued for [usize; 31]

§

impl ByteValued for [usize; 32]

§

impl ByteValued for elf64_hdr

§

impl ByteValued for elf64_note

§

impl ByteValued for elf64_phdr

§

impl ByteValued for hvm_memmap_table_entry

§

impl ByteValued for hvm_modlist_entry

§

impl ByteValued for hvm_start_info

Implementors§

Source§

impl ByteValued for mpc_bus

Source§

impl ByteValued for mpc_cpu

Source§

impl ByteValued for mpc_intsrc

Source§

impl ByteValued for mpc_ioapic

Source§

impl ByteValued for mpc_lintsrc

Source§

impl ByteValued for mpc_table

Source§

impl ByteValued for mpf_intel

Source§

impl ByteValued for vmm::devices::virtio::block::virtio::device::ConfigSpace

Source§

impl ByteValued for RequestHeader

Source§

impl ByteValued for virtio_mem_config

Source§

impl ByteValued for virtio_mem_req

Source§

impl ByteValued for virtio_mem_resp

Source§

impl ByteValued for vmm::devices::virtio::net::device::ConfigSpace

Source§

impl ByteValued for vmm::devices::virtio::pmem::device::ConfigSpace

Source§

impl ByteValued for Descriptor

Source§

impl ByteValued for UsedElement

Source§

impl ByteValued for MsixCap

§

impl ByteValued for Be16

§

impl ByteValued for Be32

§

impl ByteValued for Be64

§

impl ByteValued for BeSize

§

impl ByteValued for Le16

§

impl ByteValued for Le32

§

impl ByteValued for Le64

§

impl ByteValued for LeSize