Trait fmmap::sync::MmapFileExt
source · pub trait MmapFileExt {
Show 50 methods
// Required methods
fn len(&self) -> usize;
fn as_slice(&self) -> &[u8] ⓘ;
fn path(&self) -> &Path;
fn metadata(&self) -> Result<MetaData>;
fn is_exec(&self) -> bool;
fn lock_exclusive(&self) -> Result<()>;
fn lock_shared(&self) -> Result<()>;
fn try_lock_exclusive(&self) -> Result<()>;
fn try_lock_shared(&self) -> Result<()>;
fn unlock(&self) -> Result<()>;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn slice(&self, offset: usize, sz: usize) -> &[u8] ⓘ { ... }
fn bytes(&self, offset: usize, sz: usize) -> Result<&[u8]> { ... }
fn path_buf(&self) -> PathBuf { ... }
fn path_lossy(&self) -> Cow<'_, str> { ... }
fn path_string(&self) -> String { ... }
fn copy_all_to_vec(&self) -> Vec<u8> { ... }
fn copy_range_to_vec(&self, offset: usize, len: usize) -> Vec<u8> { ... }
fn write_all_to_new_file<P: AsRef<Path>>(
&self,
new_file_path: P
) -> Result<()> { ... }
fn write_range_to_new_file<P: AsRef<Path>>(
&self,
new_file_path: P,
offset: usize,
len: usize
) -> Result<()> { ... }
fn reader(&self, offset: usize) -> Result<MmapFileReader<'_>> { ... }
fn range_reader(
&self,
offset: usize,
len: usize
) -> Result<MmapFileReader<'_>> { ... }
fn read(&self, dst: &mut [u8], offset: usize) -> usize { ... }
fn read_exact(&self, dst: &mut [u8], offset: usize) -> Result<()> { ... }
fn read_i8(&self, offset: usize) -> Result<i8> { ... }
fn read_i16(&self, offset: usize) -> Result<i16> { ... }
fn read_i16_le(&self, offset: usize) -> Result<i16> { ... }
fn read_isize(&self, offset: usize) -> Result<isize> { ... }
fn read_isize_le(&self, offset: usize) -> Result<isize> { ... }
fn read_i32(&self, offset: usize) -> Result<i32> { ... }
fn read_i32_le(&self, offset: usize) -> Result<i32> { ... }
fn read_i64(&self, offset: usize) -> Result<i64> { ... }
fn read_i64_le(&self, offset: usize) -> Result<i64> { ... }
fn read_i128(&self, offset: usize) -> Result<i128> { ... }
fn read_i128_le(&self, offset: usize) -> Result<i128> { ... }
fn read_u8(&self, offset: usize) -> Result<u8> { ... }
fn read_u16(&self, offset: usize) -> Result<u16> { ... }
fn read_u16_le(&self, offset: usize) -> Result<u16> { ... }
fn read_usize(&self, offset: usize) -> Result<usize> { ... }
fn read_usize_le(&self, offset: usize) -> Result<usize> { ... }
fn read_u32(&self, offset: usize) -> Result<u32> { ... }
fn read_u32_le(&self, offset: usize) -> Result<u32> { ... }
fn read_u64(&self, offset: usize) -> Result<u64> { ... }
fn read_u64_le(&self, offset: usize) -> Result<u64> { ... }
fn read_u128(&self, offset: usize) -> Result<u128> { ... }
fn read_u128_le(&self, offset: usize) -> Result<u128> { ... }
fn read_f32(&self, offset: usize) -> Result<f32> { ... }
fn read_f32_le(&self, offset: usize) -> Result<f32> { ... }
fn read_f64(&self, offset: usize) -> Result<f64> { ... }
fn read_f64_le(&self, offset: usize) -> Result<f64> { ... }
}
sync
only.Expand description
Utility methods to MmapFile
Required Methods§
sourcefn metadata(&self) -> Result<MetaData>
fn metadata(&self) -> Result<MetaData>
Returns the metadata of file metadata
Metadata information about a file. This structure is returned from the metadata or symlink_metadata function or method and represents known metadata about a file such as its permissions, size, modification times, etc
sourcefn lock_exclusive(&self) -> Result<()>
fn lock_exclusive(&self) -> Result<()>
Locks the file for shared usage, blocking if the file is currently locked exclusively.
Notes
This function will do nothing if the underlying is not a real file, e.g. in-memory.
Locks the file for exclusive usage, blocking if the file is currently locked.
Notes
This function will do nothing if the underlying is not a real file, e.g. in-memory.
sourcefn try_lock_exclusive(&self) -> Result<()>
fn try_lock_exclusive(&self) -> Result<()>
Locks the file for shared usage, or returns a an error if the file is currently locked (see lock_contended_error).
Notes
This function will do nothing if the underlying is not a real file, e.g. in-memory.
Locks the file for shared usage, or returns a an error if the file is currently locked (see lock_contended_error).Locks the file for shared usage, or returns a an error if the file is currently locked (see lock_contended_error).
Notes
This function will do nothing if the underlying is not a real file, e.g. in-memory.
Provided Methods§
sourcefn slice(&self, offset: usize, sz: usize) -> &[u8] ⓘ
fn slice(&self, offset: usize, sz: usize) -> &[u8] ⓘ
slice returns data starting from offset off of size sz.
Panics
If there’s not enough data, it would panic.
sourcefn bytes(&self, offset: usize, sz: usize) -> Result<&[u8]>
fn bytes(&self, offset: usize, sz: usize) -> Result<&[u8]>
bytes returns data starting from offset off of size sz.
Errors
If there’s not enough data, it would return
Err(Error::from(ErrorKind::EOF))
.
sourcefn path_lossy(&self) -> Cow<'_, str>
fn path_lossy(&self) -> Cow<'_, str>
Returns the path lossy string of the inner file.
sourcefn path_string(&self) -> String
fn path_string(&self) -> String
Returns the path string of the inner file.
sourcefn copy_all_to_vec(&self) -> Vec<u8>
fn copy_all_to_vec(&self) -> Vec<u8>
Copy the content of the mmap file to Vec
sourcefn copy_range_to_vec(&self, offset: usize, len: usize) -> Vec<u8>
fn copy_range_to_vec(&self, offset: usize, len: usize) -> Vec<u8>
Copy a range of content of the mmap file to Vec
sourcefn write_all_to_new_file<P: AsRef<Path>>(&self, new_file_path: P) -> Result<()>
fn write_all_to_new_file<P: AsRef<Path>>(&self, new_file_path: P) -> Result<()>
Write the content of the mmap file to a new file.
sourcefn write_range_to_new_file<P: AsRef<Path>>(
&self,
new_file_path: P,
offset: usize,
len: usize
) -> Result<()>
fn write_range_to_new_file<P: AsRef<Path>>( &self, new_file_path: P, offset: usize, len: usize ) -> Result<()>
Write a range of content of the mmap file to new file.
sourcefn reader(&self, offset: usize) -> Result<MmapFileReader<'_>>
fn reader(&self, offset: usize) -> Result<MmapFileReader<'_>>
Returns a MmapFileReader
which helps read data from mmap like a normal File.
Errors
If there’s not enough data, it would return
Err(Error::from(ErrorKind::EOF))
.
sourcefn range_reader(&self, offset: usize, len: usize) -> Result<MmapFileReader<'_>>
fn range_reader(&self, offset: usize, len: usize) -> Result<MmapFileReader<'_>>
Returns a MmapFileReader
base on the given offset
and len
, which helps read data from mmap like a normal File.
Errors
If there’s not enough data, it would return
Err(Error::from(ErrorKind::EOF))
.
sourcefn read(&self, dst: &mut [u8], offset: usize) -> usize
fn read(&self, dst: &mut [u8], offset: usize) -> usize
Read bytes to the dst buf from the offset, returns how many bytes read.
sourcefn read_exact(&self, dst: &mut [u8], offset: usize) -> Result<()>
fn read_exact(&self, dst: &mut [u8], offset: usize) -> Result<()>
Read the exact number of bytes required to fill buf.
sourcefn read_i16(&self, offset: usize) -> Result<i16>
fn read_i16(&self, offset: usize) -> Result<i16>
Read a signed 16 bit integer from offset in big-endian byte order.
sourcefn read_i16_le(&self, offset: usize) -> Result<i16>
fn read_i16_le(&self, offset: usize) -> Result<i16>
Read a signed 16 bit integer from offset in little-endian byte order.
sourcefn read_isize(&self, offset: usize) -> Result<isize>
fn read_isize(&self, offset: usize) -> Result<isize>
Read a signed integer from offset in big-endian byte order.
sourcefn read_isize_le(&self, offset: usize) -> Result<isize>
fn read_isize_le(&self, offset: usize) -> Result<isize>
Read a signed integer from offset in little-endian byte order.
sourcefn read_i32(&self, offset: usize) -> Result<i32>
fn read_i32(&self, offset: usize) -> Result<i32>
Read a signed 32 bit integer from offset in big-endian byte order.
sourcefn read_i32_le(&self, offset: usize) -> Result<i32>
fn read_i32_le(&self, offset: usize) -> Result<i32>
Read a signed 32 bit integer from offset in little-endian byte order.
sourcefn read_i64(&self, offset: usize) -> Result<i64>
fn read_i64(&self, offset: usize) -> Result<i64>
Read a signed 64 bit integer from offset in big-endian byte order.
sourcefn read_i64_le(&self, offset: usize) -> Result<i64>
fn read_i64_le(&self, offset: usize) -> Result<i64>
Read a signed 64 bit integer from offset in little-endian byte order.
sourcefn read_i128(&self, offset: usize) -> Result<i128>
fn read_i128(&self, offset: usize) -> Result<i128>
Read a signed 128 bit integer from offset in big-endian byte order.
sourcefn read_i128_le(&self, offset: usize) -> Result<i128>
fn read_i128_le(&self, offset: usize) -> Result<i128>
Read a signed 128 bit integer from offset in little-endian byte order.
sourcefn read_u16(&self, offset: usize) -> Result<u16>
fn read_u16(&self, offset: usize) -> Result<u16>
Read an unsigned 16 bit integer from offset in big-endian.
sourcefn read_u16_le(&self, offset: usize) -> Result<u16>
fn read_u16_le(&self, offset: usize) -> Result<u16>
Read an unsigned 16 bit integer from offset in little-endian.
sourcefn read_usize(&self, offset: usize) -> Result<usize>
fn read_usize(&self, offset: usize) -> Result<usize>
Read an unsigned integer from offset in big-endian byte order.
sourcefn read_usize_le(&self, offset: usize) -> Result<usize>
fn read_usize_le(&self, offset: usize) -> Result<usize>
Read an unsigned integer from offset in little-endian byte order.
sourcefn read_u32(&self, offset: usize) -> Result<u32>
fn read_u32(&self, offset: usize) -> Result<u32>
Read an unsigned 32 bit integer from offset in big-endian.
sourcefn read_u32_le(&self, offset: usize) -> Result<u32>
fn read_u32_le(&self, offset: usize) -> Result<u32>
Read an unsigned 32 bit integer from offset in little-endian.
sourcefn read_u64(&self, offset: usize) -> Result<u64>
fn read_u64(&self, offset: usize) -> Result<u64>
Read an unsigned 64 bit integer from offset in big-endian.
sourcefn read_u64_le(&self, offset: usize) -> Result<u64>
fn read_u64_le(&self, offset: usize) -> Result<u64>
Read an unsigned 64 bit integer from offset in little-endian.
sourcefn read_u128(&self, offset: usize) -> Result<u128>
fn read_u128(&self, offset: usize) -> Result<u128>
Read an unsigned 128 bit integer from offset in big-endian.
sourcefn read_u128_le(&self, offset: usize) -> Result<u128>
fn read_u128_le(&self, offset: usize) -> Result<u128>
Read an unsigned 128 bit integer from offset in little-endian.
sourcefn read_f32(&self, offset: usize) -> Result<f32>
fn read_f32(&self, offset: usize) -> Result<f32>
Read an IEEE754 single-precision (4 bytes) floating point number from offset in big-endian byte order.
sourcefn read_f32_le(&self, offset: usize) -> Result<f32>
fn read_f32_le(&self, offset: usize) -> Result<f32>
Read an IEEE754 single-precision (4 bytes) floating point number from offset in little-endian byte order.
sourcefn read_f64(&self, offset: usize) -> Result<f64>
fn read_f64(&self, offset: usize) -> Result<f64>
Read an IEEE754 single-precision (8 bytes) floating point number from offset in big-endian byte order.
sourcefn read_f64_le(&self, offset: usize) -> Result<f64>
fn read_f64_le(&self, offset: usize) -> Result<f64>
Read an IEEE754 single-precision (8 bytes) floating point number from offset in little-endian byte order.