FileMapState

Struct FileMapState 

Source
pub struct FileMapState { /* private fields */ }
Expand description

Struct to manage memory range mapped from file objects.

It maps a region from a file into current process by using libc::mmap(). Then it provides safe interfaces to access the memory mapped region.

Implementations§

Source§

impl FileMapState

Source

pub fn new( file: File, offset: off_t, size: usize, writable: bool, ) -> Result<Self>

Memory map a region of the file object into current process.

It takes ownership of the file object and will close it when the returned object is dropped.

Source

pub fn size(&self) -> usize

Get size of mapped region.

Source

pub fn get_ref<T>(&self, offset: usize) -> Result<&T>

Cast a subregion of the mapped area to an object reference.

Source

pub fn get_mut<T>(&mut self, offset: usize) -> Result<&mut T>

Cast a subregion of the mapped area to an mutable object reference.

Source

pub fn get_slice<T>(&self, offset: usize, count: usize) -> Result<&[T]>

Get an immutable slice of ‘T’ at ‘offset’ with ‘count’ entries.

Source

pub fn get_slice_mut<T>( &mut self, offset: usize, count: usize, ) -> Result<&mut [T]>

Get a mutable slice of ‘T’ at ‘offset’ with ‘count’ entries.

Source

pub fn validate_range(&self, offset: usize, size: usize) -> Result<*const u8>

Check whether the range [offset, offset + size) is valid and return the start address.

Source

pub unsafe fn offset(&self, offset: usize) -> *const u8

Add offset to the base pointer.

§Safety

The caller should ensure that offset is within range.

Source

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

Sync mapped file data into disk.

Trait Implementations§

Source§

impl Default for FileMapState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for FileMapState

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for FileMapState

Source§

impl Sync for FileMapState

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> Same for T

Source§

type Output = T

Should always be Self
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.