[−][src]Struct positioned_io_preview::RandomAccessFile
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 onFile
.
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_at(&self, pos: u64, buf: &mut [u8]) -> Result<usize>
[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_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize>
[src]
fn flush(&mut self) -> Result<()>
[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
impl Send for RandomAccessFile
impl Sync for RandomAccessFile
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,