Struct ReadWriteMmap

Source
pub struct ReadWriteMmap<'a> { /* private fields */ }
Expand description

A read-write memory mapping that allows shared access to a file’s contents.

This struct provides a safe wrapper around platform-specific memory mapping implementations, allowing read and write access to a file’s contents through memory mapping. The mapping can be created with a specific offset and length.

The mapping cannot outlive the file handle it was created from.

Implementations§

Source§

impl<'a> ReadWriteMmap<'a>

Source

pub fn new( handle: &'a ReadWriteFileHandle, offset: u64, len: usize, ) -> Result<Self, MmapError>

Creates a new read-write memory mapping for the specified file handle.

§Arguments
  • handle - The file handle to create the mapping from
  • offset - The offset into the file where the mapping should begin
  • len - The length of the mapping in bytes
§Errors

Returns a MmapError if:

  • The mapping cannot be created
  • The length is zero
  • The offset and length would exceed the file size
  • The system cannot allocate the required resources
Source

pub fn as_slice(&self) -> &'a [u8]

Returns a slice of the mapped memory. The lifetime of the slice is the same as the mapping.

Source

pub fn as_mut_slice(&mut self) -> &'a mut [u8]

Returns a mutable slice of the mapped memory. The lifetime of the slice is the same as the mapping.

Source

pub fn data(&self) -> *mut u8

Returns a raw pointer to the mapped memory.

The returned pointer is adjusted for the requested offset, accounting for any page alignment requirements.

§Safety

The caller must ensure that the memory is accessed within the bounds of the mapping. The caller must also ensure the pointer does not outlast the lifetime of the mapping. It is recommended you use Self::as_slice or Self::as_mut_slice instead for compiler enforced safety.

Source

pub fn len(&self) -> usize

Returns the length of the mapped region in bytes.

This returns the originally requested length, not including any padding added for page alignment.

Source

pub fn is_empty(&self) -> bool

Returns whether the mapping is empty (zero length).

Source

pub fn advise(&self, advice: MemoryAdvice)

Provides advice to the operating system about how the memory mapping will be accessed.

§Arguments
  • advice - Bit flags indicating the expected access patterns for this memory region
§Note

This is a hint to the operating system and may be ignored. Not all advice types are supported on all platforms. On Windows, only MemoryAdvice::WILL_NEED has an effect. Multiple advice flags can be combined using bitwise operations.

Trait Implementations§

Source§

impl<'a> Clone for ReadWriteMmap<'a>

Source§

fn clone(&self) -> ReadWriteMmap<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ReadWriteMmap<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Ord for ReadWriteMmap<'a>

Source§

fn cmp(&self, other: &ReadWriteMmap<'a>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a> PartialEq for ReadWriteMmap<'a>

Source§

fn eq(&self, other: &ReadWriteMmap<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialOrd for ReadWriteMmap<'a>

Source§

fn partial_cmp(&self, other: &ReadWriteMmap<'a>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a> Eq for ReadWriteMmap<'a>

Source§

impl<'a> StructuralPartialEq for ReadWriteMmap<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ReadWriteMmap<'a>

§

impl<'a> RefUnwindSafe for ReadWriteMmap<'a>

§

impl<'a> !Send for ReadWriteMmap<'a>

§

impl<'a> !Sync for ReadWriteMmap<'a>

§

impl<'a> Unpin for ReadWriteMmap<'a>

§

impl<'a> UnwindSafe for ReadWriteMmap<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.