Struct fmmap::raw::tokio::AsyncDiskMmapFile
source · pub struct AsyncDiskMmapFile { /* private fields */ }
Available on crate features
tokio
and async-trait
only.Expand description
AsyncDiskMmapFile contains an immutable mmap buffer and a read-only file.
Implementations§
source§impl AsyncDiskMmapFile
impl AsyncDiskMmapFile
sourcepub async fn open<P: AsRef<Path>>(path: P) -> Result<Self, Error>
pub async fn open<P: AsRef<Path>>(path: P) -> Result<Self, Error>
Open a readable memory map backed by a file
Examples
ⓘ
use fmmap::tokio::AsyncMmapFileExt;
use fmmap::raw::tokio::AsyncDiskMmapFile;
// mmap the file
let mut file = AsyncDiskMmapFile::open("tokio_async_disk_open_test.txt").await.unwrap();
let mut buf = vec![0; "some data...".len()];
file.read_exact(buf.as_mut_slice(), 0).unwrap();
assert_eq!(buf.as_slice(), "some data...".as_bytes());
sourcepub async fn open_with_options<P: AsRef<Path>>(
path: P,
opts: AsyncOptions
) -> Result<Self, Error>
pub async fn open_with_options<P: AsRef<Path>>( path: P, opts: AsyncOptions ) -> Result<Self, Error>
Open a readable memory map backed by a file with AsyncOptions
Examples
ⓘ
use fmmap::tokio::{AsyncOptions, AsyncMmapFileExt};
use fmmap::raw::tokio::AsyncDiskMmapFile;
// mmap the file
let opts = AsyncOptions::new()
// mmap content after the sanity text
.offset("sanity text".as_bytes().len() as u64);
// mmap the file
let mut file = AsyncDiskMmapFile::open_with_options("tokio_async_disk_open_with_options_test.txt", opts).await.unwrap();
let mut buf = vec![0; "some data...".len()];
file.read_exact(buf.as_mut_slice(), 0).unwrap();
assert_eq!(buf.as_slice(), "some data...".as_bytes());
sourcepub async fn open_exec<P: AsRef<Path>>(path: P) -> Result<Self, Error>
pub async fn open_exec<P: AsRef<Path>>(path: P) -> Result<Self, Error>
Open a readable and executable memory map backed by a file
Examples
ⓘ
use fmmap::tokio::AsyncMmapFileExt;
use fmmap::raw::tokio::AsyncDiskMmapFile;
// mmap the file
let mut file = AsyncDiskMmapFile::open_exec("tokio_async_disk_open_exec_test.txt").await.unwrap();
let mut buf = vec![0; "some data...".len()];
file.read_exact(buf.as_mut_slice(), 0).unwrap();
assert_eq!(buf.as_slice(), "some data...".as_bytes());
sourcepub async fn open_exec_with_options<P: AsRef<Path>>(
path: P,
opts: AsyncOptions
) -> Result<Self, Error>
pub async fn open_exec_with_options<P: AsRef<Path>>( path: P, opts: AsyncOptions ) -> Result<Self, Error>
Open a readable and executable memory map backed by a file with AsyncOptions
.
Examples
ⓘ
use fmmap::tokio::{AsyncOptions, AsyncMmapFileExt};
use fmmap::raw::tokio::AsyncDiskMmapFile;
// mmap the file
let opts = AsyncOptions::new()
// mmap content after the sanity text
.offset("sanity text".as_bytes().len() as u64);
// mmap the file
let mut file = AsyncDiskMmapFile::open_exec_with_options("tokio_async_disk_open_exec_with_options_test.txt", opts).await.unwrap();
let mut buf = vec![0; "some data...".len()];
file.read_exact(buf.as_mut_slice(), 0).unwrap();
assert_eq!(buf.as_slice(), "some data...".as_bytes());
Trait Implementations§
source§impl AsyncMmapFileExt for AsyncDiskMmapFile
impl AsyncMmapFileExt for AsyncDiskMmapFile
source§fn metadata<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<MetaData>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn metadata<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<MetaData>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Returns the metadata of file metadata Read more
source§fn lock_exclusive(&self) -> Result<()>
fn lock_exclusive(&self) -> Result<()>
Locks the file for shared usage, blocking if the file is currently locked exclusively. Read more
Locks the file for exclusive usage, blocking if the file is currently locked. Read more
source§fn 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). Read more
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). Read more
source§fn 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. Read more
source§fn 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. Read more
source§fn path_lossy(&self) -> Cow<'_, str>
fn path_lossy(&self) -> Cow<'_, str>
Returns the path lossy string of the inner file.
source§fn path_string(&self) -> String
fn path_string(&self) -> String
Returns the path string of the inner file.
source§fn copy_all_to_vec(&self) -> Vec<u8>
fn copy_all_to_vec(&self) -> Vec<u8>
Copy the content of the mmap file to Vec
source§fn 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
source§fn write_all_to_new_file<'life0, 'async_trait, P>(
&'life0 self,
new_file_path: P
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
P: 'async_trait + AsRef<Path> + Send + Sync,
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn write_all_to_new_file<'life0, 'async_trait, P>( &'life0 self, new_file_path: P ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where P: 'async_trait + AsRef<Path> + Send + Sync, Self: Sync + 'async_trait, 'life0: 'async_trait,
Write the content of the mmap file to a new file.
source§fn write_range_to_new_file<'life0, 'async_trait, P>(
&'life0 self,
new_file_path: P,
offset: usize,
len: usize
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
P: 'async_trait + AsRef<Path> + Send + Sync,
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn write_range_to_new_file<'life0, 'async_trait, P>( &'life0 self, new_file_path: P, offset: usize, len: usize ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where P: 'async_trait + AsRef<Path> + Send + Sync, Self: Sync + 'async_trait, 'life0: 'async_trait,
Write a range of content of the mmap file to new file.
source§fn reader(&self, offset: usize) -> Result<AsyncMmapFileReader<'_>>
fn reader(&self, offset: usize) -> Result<AsyncMmapFileReader<'_>>
Returns a
AsyncMmapFileReader
which helps read data from mmap like a normal File. Read moresource§fn range_reader(
&self,
offset: usize,
len: usize
) -> Result<AsyncMmapFileReader<'_>>
fn range_reader( &self, offset: usize, len: usize ) -> Result<AsyncMmapFileReader<'_>>
Returns a
AsyncMmapFileReader
base on the given offset
and len
, which helps read data from mmap like a normal File. Read moresource§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§fn 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.
source§impl From<AsyncDiskMmapFile> for AsyncMmapFile
impl From<AsyncDiskMmapFile> for AsyncMmapFile
source§fn from(file: AsyncDiskMmapFile) -> Self
fn from(file: AsyncDiskMmapFile) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl !RefUnwindSafe for AsyncDiskMmapFile
impl Send for AsyncDiskMmapFile
impl Sync for AsyncDiskMmapFile
impl Unpin for AsyncDiskMmapFile
impl !UnwindSafe for AsyncDiskMmapFile
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