Skip to main content

WriteTo

Trait WriteTo 

Source
pub trait WriteTo {
    // Required method
    fn write_to(&self, cowfile: &CowFile, offset: usize) -> Result<()>;
}
Expand description

Trait for types that can be serialized into a CowFile at a given offset.

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

§Examples

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

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

impl WriteTo for Pair {
    fn write_to(&self, pf: &CowFile, offset: usize) -> Result<()> {
        pf.write_le::<u32>(offset, self.a)?;
        pf.write_le::<u32>(offset + 4, self.b)?;
        Ok(())
    }
}

Required Methods§

Source

fn write_to(&self, cowfile: &CowFile, offset: usize) -> Result<()>

Serializes this value into the given cowfile at offset.

§Errors

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

Implementors§