Skip to main content

OnDiskStruct

Trait OnDiskStruct 

Source
pub(crate) trait OnDiskStruct: Sized {
    const ON_DISK_SIZE: usize;

    // Required methods
    fn load_from(bytes: &[u8]) -> Result<Self>;
    fn store_to(&self, bytes: &mut [u8]) -> Result<()>;

    // Provided methods
    fn on_disk_size(&self) -> usize { ... }
    fn load_from_le(bytes: &[u8]) -> Result<Self> { ... }
    fn store_to_le(&self, bytes: &mut [u8]) -> Result<()> { ... }
    fn load_from_be(bytes: &[u8]) -> Result<Self> { ... }
    fn store_to_be(&self, bytes: &mut [u8]) -> Result<()> { ... }
}
Expand description

A structure to be loaded from or stored on disk (e.g. qcow2 image header), in binary format.

Required Associated Constants§

Source

const ON_DISK_SIZE: usize

The on-disk size of this structure, in bytes

Required Methods§

Source

fn load_from(bytes: &[u8]) -> Result<Self>

Load this structure from the given slice, in default inherent endianness.

Source

fn store_to(&self, bytes: &mut [u8]) -> Result<()>

Store this structure in the given slice, in default inherent endianness.

Provided Methods§

Source

fn on_disk_size(&self) -> usize

Convenience alias for Self::ON_DISK_SIZE for objects

Source

fn load_from_le(bytes: &[u8]) -> Result<Self>

Load this structure from the given slice.

Use little endian, unless the structure has a specific inherent endianness.

Source

fn store_to_le(&self, bytes: &mut [u8]) -> Result<()>

Store this structure in the given slice.

Use little endian, unless the structure has a specific inherent endianness.

Source

fn load_from_be(bytes: &[u8]) -> Result<Self>

Load this structure from the given slice.

Use big endian, unless the structure has a specific inherent endianness.

Source

fn store_to_be(&self, bytes: &mut [u8]) -> Result<()>

Store this structure in the given slice.

Use big endian, unless the structure has a specific inherent endianness.

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 OnDiskStruct for u16

Source§

const ON_DISK_SIZE: usize

Source§

fn load_from_le(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_le(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from_be(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_be(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from(bytes: &[u8]) -> Result<Self>

Source§

fn store_to(&self, bytes: &mut [u8]) -> Result<()>

Source§

impl OnDiskStruct for u32

Source§

const ON_DISK_SIZE: usize

Source§

fn load_from_le(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_le(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from_be(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_be(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from(bytes: &[u8]) -> Result<Self>

Source§

fn store_to(&self, bytes: &mut [u8]) -> Result<()>

Source§

impl OnDiskStruct for u64

Source§

const ON_DISK_SIZE: usize

Source§

fn load_from_le(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_le(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from_be(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_be(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from(bytes: &[u8]) -> Result<Self>

Source§

fn store_to(&self, bytes: &mut [u8]) -> Result<()>

Source§

impl OnDiskStruct for AtomicU32

Source§

const ON_DISK_SIZE: usize

Source§

fn load_from_le(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_le(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from_be(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_be(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from(bytes: &[u8]) -> Result<Self>

Source§

fn store_to(&self, bytes: &mut [u8]) -> Result<()>

Source§

impl OnDiskStruct for AtomicU64

Source§

const ON_DISK_SIZE: usize

Source§

fn load_from_le(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_le(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from_be(bytes: &[u8]) -> Result<Self>

Source§

fn store_to_be(&self, bytes: &mut [u8]) -> Result<()>

Source§

fn load_from(bytes: &[u8]) -> Result<Self>

Source§

fn store_to(&self, bytes: &mut [u8]) -> Result<()>

Implementors§