Struct mmap_safe::MappedFile
source · pub struct MappedFile { /* private fields */ }
Expand description
A thin, safe wrapper for memory-mapped files.
This wrapper ensures memory safety by only providing one mutable reference at a time and by locking the file exclusively.
Implementations§
source§impl MappedFile
impl MappedFile
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn create<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn new(file: File) -> Result<Self>
sourcepub fn map(&self, offset: u64, size: usize) -> Result<Mapping<'_>>
pub fn map(&self, offset: u64, size: usize) -> Result<Mapping<'_>>
Returns mapped memory for the file.
sourcepub fn map_mut<'a>(
&'a mut self,
offset: u64,
size: usize
) -> Result<MutMapping<'a>>
pub fn map_mut<'a>(
&'a mut self,
offset: u64,
size: usize
) -> Result<MutMapping<'a>>
Returns mutably-mapped memory for the file.
sourcepub fn resize(&mut self, size: u64) -> Result<()>
pub fn resize(&mut self, size: u64) -> Result<()>
Resizes the file. When grown, it is guaranteed that all mapped memory regions on this file stay valid. When the file gets shrunk, the behaviour of regions behind the new end of the file is undefined.
sourcepub fn sync_data(&mut self) -> Result<()>
pub fn sync_data(&mut self) -> Result<()>
See File::sync_data
sourcepub fn sync_all(&mut self) -> Result<()>
pub fn sync_all(&mut self) -> Result<()>
See File::sync_all
sourcepub fn into_mut_mapping(
self,
offset: u64,
size: usize
) -> Result<IntoMutMapping, (Error, Self)>
pub fn into_mut_mapping(
self,
offset: u64,
size: usize
) -> Result<IntoMutMapping, (Error, Self)>
Converts this instance into a mutable mapping.
If you want to convert it back, call IntoMutMapping::unmap
.