Trait ioat::ReadAt [] [src]

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

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

The ReadAt trait allows for atomically reading bytes from a source at specific offsets.

As an example, this trait is implemented by File. Unlike Read, however, it is not implemented for &File, since the implementation is not thread-safe. If two threads where to call read_at at once, a race condition could occur, where one thread seeks and the other thread reads.

For this reason, ReadAt is not automatically implemented for all Read + Seek types. If a Read + Seek type is guaranteed to not seek in parallel with a call to read_at, it can be wrapped in AssertThreadSafe.

Required Methods

Reads some bytes from pos bytes into the source.

This method returns the number of bytes read or an error, if the bytes could not be read. If Ok(n) is returned, then it is guaranteed, that 0 <= n <= buf.len().

Errors

This method can return any I/O error.

Provided Methods

Reads exactly buf.len() bytes from pos bytes into the source.

This is usually handled by repeatedly calling read_at until the buffer is full. This method is an analogue to read_exact for Read.

Errors

If read_at() returns an error, then this method immediately propagates that error by returning.

If read_at() returns Ok(0) to indicate the end of the source has been reached before buf has been filled, then this method errs with an error of kind UnexpectedEof. Any bytes read up until this point are discarded.

Implementors