Skip to main content

ReadFrom

Trait ReadFrom 

Source
pub trait ReadFrom: Sized {
    // Required method
    fn read_from(cowfile: &CowFile, offset: usize) -> Result<Self>;
}
Expand description

Trait for types that can be deserialized from a CowFile at a given offset.

Implement this for user-defined structs to enable CowFile::read_type.

§Examples

use cowfile::{CowFile, ReadFrom, Result};

struct Pair {
    a: u32,
    b: u32,
}

impl ReadFrom for Pair {
    fn read_from(pf: &CowFile, offset: usize) -> Result<Self> {
        Ok(Pair {
            a: pf.read_le::<u32>(offset)?,
            b: pf.read_le::<u32>(offset + 4)?,
        })
    }
}

Required Methods§

Source

fn read_from(cowfile: &CowFile, offset: usize) -> Result<Self>

Reads and deserializes a value from the given cowfile at offset.

§Errors

Returns an error if the underlying reads fail (e.g., out of bounds).

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.

Implementors§