[][src]Struct positioned_io_preview::RandomAccessFile

pub struct RandomAccessFile { /* fields omitted */ }

A wrapper for File that provides optimized random access through ReadAt and WriteAt.

  • On Unix the operating system is advised that reads will be in random order (FADV_RANDOM).
  • On Windows the implementation is orders of magnitude faster than ReadAt directly on File.

Examples

Read the fifth 512-byte sector of a file:

use positioned_io::{RandomAccessFile, ReadAt};

// open a file (note: binding does not need to be mut)
let raf = RandomAccessFile::open("tests/pi.txt")?;

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

Methods

impl RandomAccessFile[src]

pub fn open<P: AsRef<Path>>(path: P) -> Result<RandomAccessFile>[src]

Opens a file for random access.

pub fn try_new(file: File) -> Result<RandomAccessFile>[src]

Creates a RandomAccessFile wrapper around a File.

pub fn try_into_inner(self) -> Result<File, (RandomAccessFile, Error)>[src]

Tries to unwrap the inner File.

Trait Implementations

impl ReadAt for RandomAccessFile[src]

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

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

impl WriteAt for RandomAccessFile[src]

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

Writes a complete buffer at an offset. Read more

impl Debug for RandomAccessFile[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]