Skip to main content

WriteSeekExt

Trait WriteSeekExt 

Source
pub trait WriteSeekExt: Write + Seek {
    // Required method
    fn write_all_at_preserving_position(
        &mut self,
        offset: u64,
        buffer: &[u8],
    ) -> Result<()>;
}
Expand description

Extension methods for values that implement both Write and Seek.

WriteSeekExt provides position-preserving write helpers for random-access output use cases such as patching headers, offsets, and indexes after a stream has already been written.

Required Methods§

Source

fn write_all_at_preserving_position( &mut self, offset: u64, buffer: &[u8], ) -> Result<()>

Writes all bytes at offset and restores the original position.

This method seeks to offset, delegates to Write::write_all, and then restores the position that was current before the call.

§Parameters
  • offset: Absolute byte offset from the start of the stream.
  • buffer: Bytes to write.
§Errors

Returns an error when reading the current position, seeking to offset, writing bytes, or restoring the original position fails. If restoration fails, the restoration error is returned.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> WriteSeekExt for T
where T: Write + Seek + ?Sized,