Struct positioned_io_preview::RandomAccessFile
source · pub struct RandomAccessFile { /* private fields */ }
Expand description
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)?;
Implementations
sourceimpl RandomAccessFile
impl RandomAccessFile
sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<RandomAccessFile>
pub fn open<P: AsRef<Path>>(path: P) -> Result<RandomAccessFile>
Opens a file for random access.
sourcepub fn try_new(file: File) -> Result<RandomAccessFile>
pub fn try_new(file: File) -> Result<RandomAccessFile>
Creates a RandomAccessFile
wrapper around a File
.
sourcepub fn try_into_inner(self) -> Result<File, (RandomAccessFile, Error)>
pub fn try_into_inner(self) -> Result<File, (RandomAccessFile, Error)>
Tries to unwrap the inner File
.
Trait Implementations
sourceimpl Debug for RandomAccessFile
impl Debug for RandomAccessFile
sourceimpl ReadAt for RandomAccessFile
impl ReadAt for RandomAccessFile
sourceimpl WriteAt for RandomAccessFile
impl WriteAt for RandomAccessFile
Auto Trait Implementations
impl RefUnwindSafe for RandomAccessFile
impl Send for RandomAccessFile
impl Sync for RandomAccessFile
impl Unpin for RandomAccessFile
impl UnwindSafe for RandomAccessFile
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more