Trait positioned_io::WriteAt [] [src]

pub trait WriteAt {
    fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>;
    fn flush(&mut self) -> Result<()>;

    fn write_all_at(&mut self, pos: u64, buf: &[u8]) -> Result<()> { ... }

Trait for writing at an offset.

Implementations should be able to write bytes at an offset, without changing any sort of write-position. Self should not change at all.


use positioned_io::WriteAt;
use byteorder::{ByteOrder, LittleEndian};

// Put the integer in a buffer.
let mut buf = vec![0; 4];
LittleEndian::write_u32(&mut buf, 1234);

// Write it to the file.
let mut file = try!(OpenOptions::new().write(true).open(""));
try!(file.write_all_at(1 << 20, &buf));

Required Methods

Write a buffer at an offset, returning the number of bytes written.

This function may write fewer bytes than the size of buf, for example if it is interrupted.

See Write::write().

Flush this writer, ensuring that any buffered data is written.

This should rarely do anything, since buffering is not very useful for positioned writes.

Provided Methods

Write a complete buffer at an offset.

If only a lesser number of bytes can be written, will yield an error.