MappedFile: Added generic into_inner(), inner_mut(), and inner() accessors.

Fortune for mapped-file's current commit: Small blessing − 小吉
master
Avril 1 year ago
parent d74946934d
commit 08c93f2af0
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -2,7 +2,7 @@
name = "mapped-file"
description = "Construct a memory mapping over any file object"
keywords = ["unix", "mmap", "generic", "file", "fd"]
version = "0.0.6"
version = "0.0.7"
edition = "2021"
repository="https://github.com/notflan/mapped-file"
license="MIT"

@ -101,6 +101,36 @@ pub fn get_page_size() -> usize
v as usize
}
impl<T> MappedFile<T> {
/// A reference to the mapped backing file
#[inline]
pub fn inner(&self) -> &T
{
&self.file
}
/// A mutable reference to the mapped backing file
///
/// # Note
/// Behaviour of faulted or unfaulted pages is not specified if the backing file is modified another way. Likewise, if the backing file is read from another way, the data mapped is not guaranteed to have been synced unless a `flush()` has completed. Be careful with this.
#[inline]
pub fn inner_mut(&mut self) -> &mut T
{
&mut self.file
}
/// Unmap the memory contained in `T` and return it.
///
/// # Warning
/// If the map is shared, or refers to a persistent file on disk, you should call `flush()`
/// first or use `into_inner_synced()`
#[inline]
pub fn into_inner(self) -> T
{
drop(self.map);
self.file
}
}
impl<T: AsRawFd> MappedFile<T> {
/// Map the file `file` to `len` bytes with memory protection as provided by `perm`, and mapping flags provided by `flags`.
/// # Mapping flags
@ -429,18 +459,6 @@ impl<T> MappedFile<T> {
}, file)
}
/// Unmap the memory contained in `T` and return it.
///
/// # Warning
/// If the map is shared, or refers to a persistent file on disk, you should call `flush()`
/// first or use `into_inner_synced()`
#[inline]
pub fn into_inner(self) -> T
{
drop(self.map);
self.file
}
/// The size of the mapped memory
#[inline]
pub fn len(&self) -> usize

Loading…
Cancel
Save