pub struct Mmap {
pub size: u64,
/* private fields */
}
Expand description
A struct that represents a memory-mapped file.
Fields§
§size: u64
Implementations§
Source§impl Mmap
impl Mmap
Sourcepub fn new(path: &Path) -> Result<Self, MmapError>
pub fn new(path: &Path) -> Result<Self, MmapError>
Creates a new Mmap
instance by opening the file at the given path
.
§Arguments
path
- The path to the file to be memory-mapped.
§Returns
A Result
containing the Mmap
instance or a MmapError
if the operation fails.
§Errors
This function may return the following errors:
ErrFdNotAvail
: The file descriptor is not available for mapping.ErrInvalidFd
: The file descriptor is invalid.ErrUnaligned
: The mapping is not properly aligned.ErrNoMapSupport
: The file system does not support memory mapping.ErrNoMem
: There is not enough memory available to complete the operation.ErrUnknown(code)
: An unknown error occurred with the given OS error code.
Sourcepub fn overwrite_with<F>(
&self,
offset: usize,
len: usize,
writer: F,
) -> Result<(), Error>
pub fn overwrite_with<F>( &self, offset: usize, len: usize, writer: F, ) -> Result<(), Error>
Overwrites data in the memory-mapped file using a custom writer function.
§Arguments
offset
- The offset in the file where the data should be overwritten.len
- The length of the data to be written.writer
- A closure that writes the data to the file.
§Returns
A Result
containing the unit type (()
) or an io::Error
if the operation fails.
Sourcepub fn read_with<F>(
&self,
offset: usize,
len: usize,
reader: F,
) -> Result<(), Error>
pub fn read_with<F>( &self, offset: usize, len: usize, reader: F, ) -> Result<(), Error>
Reads data from the memory-mapped file at the specified offset using a custom reader function.
§Arguments
offset
- The offset in the file where the data should be read from.len
- The length of the data to be read.reader
- A closure that reads the data from the file.
§Returns
A Result
containing the number of bytes read or an io::Error
if the operation fails.
Auto Trait Implementations§
impl Freeze for Mmap
impl RefUnwindSafe for Mmap
impl !Send for Mmap
impl !Sync for Mmap
impl Unpin for Mmap
impl UnwindSafe for Mmap
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