[][src]Trait positioned_io_preview::ReadAt

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

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

Trait for reading bytes at an offset.

Implementations should be able to read bytes without changing any sort of read position. Self should not change at all. Buffering reads is unlikely to be useful, since each time read_at() is called, the position may be completely different.

Examples

Read the fifth 512-byte sector of a file:

use std::fs::File;
use positioned_io::ReadAt;

// note that file does not need to be mut
let file = File::open("tests/pi.txt")?;

// read up to 512 bytes
let mut buf = [0; 512];
let bytes_read = file.read_at(2048, &mut buf)?;

Required methods

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

Reads bytes from an offset in this source into a buffer, returning how many bytes were read.

This function may yield fewer bytes than the size of buf, if it was interrupted or hit the "end of file".

See Read::read() for details.

Loading content...

Provided methods

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

Reads the exact number of bytes required to fill buf from an offset.

Errors if the "end of file" is encountered before filling the buffer.

See Read::read_exact() for details.

Loading content...

Implementations on Foreign Types

impl ReadAt for File[src]

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

impl<'a> ReadAt for &'a [u8][src]

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

impl<'a> ReadAt for &'a mut [u8][src]

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

impl ReadAt for Vec<u8>[src]

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

impl<'a, R: ReadAt + ?Sized> ReadAt for &'a R[src]

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

impl<'a, R: ReadAt + ?Sized> ReadAt for &'a mut R[src]

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

impl<'a, R: ReadAt> ReadAt for &'a RefCell<R>[src]

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

Loading content...

Implementors

impl ReadAt for RandomAccessFile[src]

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

impl<I: ReadAt> ReadAt for Slice<I>[src]

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

impl<I: ReadAt, E: ByteOrder> ReadAt for ByteIo<I, E>[src]

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

Loading content...