Struct 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

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Source

pub fn create<P: AsRef<Path>>(path: P) -> Result<Self>

Source

pub fn new(file: File) -> Result<Self>

Source

pub fn map(&self, offset: u64, size: usize) -> Result<Mapping<'_>>

Returns mapped memory for the file.

Source

pub fn map_mut<'a>( &'a mut self, offset: u64, size: usize, ) -> Result<MutMapping<'a>>

Returns mutably-mapped memory for the file.

Source

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.

Source

pub fn size(&self) -> u64

Returns the current size of the file.

Source

pub fn sync_data(&mut self) -> Result<()>

Source

pub fn sync_all(&mut self) -> Result<()>

Source

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.

Trait Implementations§

Source§

impl Drop for MappedFile

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.