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§
Sourceconst ON_DISK_SIZE: usize
const ON_DISK_SIZE: usize
The on-disk size of this structure, in bytes
Required Methods§
Provided Methods§
Sourcefn on_disk_size(&self) -> usize
fn on_disk_size(&self) -> usize
Convenience alias for Self::ON_DISK_SIZE for objects
Sourcefn load_from_le(bytes: &[u8]) -> Result<Self>
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.
Sourcefn store_to_le(&self, bytes: &mut [u8]) -> Result<()>
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.
Sourcefn load_from_be(bytes: &[u8]) -> Result<Self>
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.
Sourcefn store_to_be(&self, bytes: &mut [u8]) -> Result<()>
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.