diff --git a/Cargo.toml b/Cargo.toml index c2f87f0..0c801bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index 870fe31..b88bd8a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,6 +101,36 @@ pub fn get_page_size() -> usize v as usize } +impl MappedFile { + /// 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 MappedFile { /// 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 MappedFile { }, 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