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
ReadAtdirectly 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§
Source§impl RandomAccessFile
impl RandomAccessFile
Sourcepub fn try_new(file: File) -> Result<RandomAccessFile, Error>
pub fn try_new(file: File) -> Result<RandomAccessFile, Error>
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§
Source§impl Debug for RandomAccessFile
impl Debug for RandomAccessFile
Source§impl ReadAt for RandomAccessFile
impl ReadAt for RandomAccessFile
Source§impl Size for RandomAccessFile
impl Size for RandomAccessFile
Source§impl WriteAt for &RandomAccessFile
impl WriteAt for &RandomAccessFile
Source§fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize, Error>
fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize, Error>
Writes bytes from a buffer to an offset, returning the number of bytes
written. Read more
Source§impl WriteAt for RandomAccessFile
impl WriteAt for RandomAccessFile
Source§fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize, Error>
fn write_at(&mut self, pos: u64, buf: &[u8]) -> Result<usize, Error>
Writes bytes from a buffer to an offset, returning the number of bytes
written. Read more
Auto Trait Implementations§
impl Freeze for RandomAccessFile
impl RefUnwindSafe for RandomAccessFile
impl Send for RandomAccessFile
impl Sync for RandomAccessFile
impl Unpin for RandomAccessFile
impl UnwindSafe for RandomAccessFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more