Struct positioned_io::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§
source§impl 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§
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§impl 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§
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
source§impl<R> ReadBytesAtExt for Rwhere
R: ReadAt,
impl<R> ReadBytesAtExt for Rwhere R: ReadAt,
source§fn read_u16_at<T: ByteOrder>(&self, pos: u64) -> Result<u16>
fn read_u16_at<T: ByteOrder>(&self, pos: u64) -> Result<u16>
Reads an unsigned 16-bit integer at an offset.
source§fn read_i16_at<T: ByteOrder>(&self, pos: u64) -> Result<i16>
fn read_i16_at<T: ByteOrder>(&self, pos: u64) -> Result<i16>
Reads a signed 16-bit integer at an offset.
source§fn read_u32_at<T: ByteOrder>(&self, pos: u64) -> Result<u32>
fn read_u32_at<T: ByteOrder>(&self, pos: u64) -> Result<u32>
Reads an unsigned 32-bit integer at an offset.
source§fn read_i32_at<T: ByteOrder>(&self, pos: u64) -> Result<i32>
fn read_i32_at<T: ByteOrder>(&self, pos: u64) -> Result<i32>
Reads a signed 32-bit integer at an offset.
source§fn read_u64_at<T: ByteOrder>(&self, pos: u64) -> Result<u64>
fn read_u64_at<T: ByteOrder>(&self, pos: u64) -> Result<u64>
Reads an unsigned 64-bit integer at an offset.
source§fn read_i64_at<T: ByteOrder>(&self, pos: u64) -> Result<i64>
fn read_i64_at<T: ByteOrder>(&self, pos: u64) -> Result<i64>
Reads a signed 64-bit integer at an offset.
source§fn read_uint_at<T: ByteOrder>(&self, pos: u64, nbytes: usize) -> Result<u64>
fn read_uint_at<T: ByteOrder>(&self, pos: u64, nbytes: usize) -> Result<u64>
Reads an unsigned
nbytes
-bit integer at an offset.source§fn read_int_at<T: ByteOrder>(&self, pos: u64, nbytes: usize) -> Result<i64>
fn read_int_at<T: ByteOrder>(&self, pos: u64, nbytes: usize) -> Result<i64>
Reads a signed
nbytes
-bit integer at an offset.source§impl<W> WriteBytesAtExt for Wwhere
W: WriteAt,
impl<W> WriteBytesAtExt for Wwhere W: WriteAt,
source§fn write_u8_at(&mut self, pos: u64, n: u8) -> Result<()>
fn write_u8_at(&mut self, pos: u64, n: u8) -> Result<()>
Writes an unsigned 8-bit integer to an offset.
source§fn write_i8_at(&mut self, pos: u64, n: i8) -> Result<()>
fn write_i8_at(&mut self, pos: u64, n: i8) -> Result<()>
Writes a signed 8-bit integer to an offset.
source§fn write_u16_at<T: ByteOrder>(&mut self, pos: u64, n: u16) -> Result<()>
fn write_u16_at<T: ByteOrder>(&mut self, pos: u64, n: u16) -> Result<()>
Writes an unsigned 16-bit integer to an offset.
source§fn write_i16_at<T: ByteOrder>(&mut self, pos: u64, n: i16) -> Result<()>
fn write_i16_at<T: ByteOrder>(&mut self, pos: u64, n: i16) -> Result<()>
Writes a signed 16-bit integer to an offset.
source§fn write_u32_at<T: ByteOrder>(&mut self, pos: u64, n: u32) -> Result<()>
fn write_u32_at<T: ByteOrder>(&mut self, pos: u64, n: u32) -> Result<()>
Writes an unsigned 32-bit integer to an offset.
source§fn write_i32_at<T: ByteOrder>(&mut self, pos: u64, n: i32) -> Result<()>
fn write_i32_at<T: ByteOrder>(&mut self, pos: u64, n: i32) -> Result<()>
Writes a signed 32-bit integer to an offset.
source§fn write_u64_at<T: ByteOrder>(&mut self, pos: u64, n: u64) -> Result<()>
fn write_u64_at<T: ByteOrder>(&mut self, pos: u64, n: u64) -> Result<()>
Writes an unsigned 64-bit integer to an offset.
source§fn write_i64_at<T: ByteOrder>(&mut self, pos: u64, n: i64) -> Result<()>
fn write_i64_at<T: ByteOrder>(&mut self, pos: u64, n: i64) -> Result<()>
Writes a signed 64-bit integer to an offset.
source§fn write_uint_at<T: ByteOrder>(
&mut self,
pos: u64,
n: u64,
nbytes: usize
) -> Result<()>
fn write_uint_at<T: ByteOrder>( &mut self, pos: u64, n: u64, nbytes: usize ) -> Result<()>
Writes an unsigned
nbytes
-bit integer to an offset.source§fn write_int_at<T: ByteOrder>(
&mut self,
pos: u64,
n: i64,
nbytes: usize
) -> Result<()>
fn write_int_at<T: ByteOrder>( &mut self, pos: u64, n: i64, nbytes: usize ) -> Result<()>
Writes a signed
nbytes
-bit integer to an offset.