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

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

Trait for writing bytes 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.

When writing beyond the end of the underlying object it is extended and intermediate bytes are filled with the value 0.

Examples

use std::fs::OpenOptions;
use positioned_io::WriteAt;

let mut file = OpenOptions::new().write(true).open("tests/pi.txt")?;

// write some bytes
let bytes_written = file.write_at(2, b"1415926535897932384626433")?;

Required Methods§

source

fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>

Writes bytes from a buffer to 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() for details.

source

fn flush(&mut self) -> Result<()>

Flush this writer, ensuring that any intermediately buffered data reaches its destination.

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

This should be equivalent to Write::flush(), so it does not actually sync changes to disk when writing a File. Use File::sync_data() instead.

Provided Methods§

source

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

Writes a complete buffer at an offset.

Errors if it could not write the entire buffer.

See Write::write_all() for details.

Implementations on Foreign Types§

source§

impl WriteAt for Vec<u8>

source§

fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

source§

impl WriteAt for File

source§

fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

source§

impl<'a> WriteAt for &'a mut [u8]

source§

fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

source§

impl<'a, W: WriteAt + ?Sized> WriteAt for &'a mut W

source§

fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

source§

impl<'a, W: WriteAt> WriteAt for &'a RefCell<W>

source§

fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

source§

impl<R: WriteAt + ?Sized> WriteAt for Box<R>

source§

fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

Implementors§