Struct OwnedReadWriteMmap

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

An owned version of ReadWriteMmap that owns its file handle via Arc, making it safe to send across threads and allowing multiple mappings to share the same handle.

Implementations§

Source§

impl OwnedReadWriteMmap

Source

pub fn handle(&self) -> Arc<ReadWriteFileHandle>

Returns a reference to the underlying file handle

Source

pub unsafe fn new( handle: Arc<ReadWriteFileHandle>, offset: u64, length: usize, ) -> Result<Self, MmapError>

Creates a new owned memory mapping from a file handle.

§Arguments
  • handle - The file handle to map, wrapped in an Arc for shared ownership
  • offset - The offset into the file to start the mapping
  • length - The length of the mapping
§Safety

This function is unsafe because it creates a new memory mapping. The caller must ensure:

  • The handle is valid and has appropriate permissions
  • The offset and length are valid for the file
  • The mapping will not be used after the OwnedReadWriteMmap is dropped
  • Concurrent writes to the same region of the file may result in undefined behavior
Source

pub unsafe fn from_handle( handle: ReadWriteFileHandle, offset: u64, length: usize, ) -> Result<Self, MmapError>

Creates a new owned memory mapping from a file handle, automatically wrapping it in an Arc.

This is a convenience constructor that takes ownership of a ReadWriteFileHandle and wraps it in an Arc.

§Arguments
  • handle - The file handle to map
  • offset - The offset into the file to start the mapping
  • length - The length of the mapping
§Safety

Same safety requirements as new().

Methods from Deref<Target = ReadWriteMmap<'static>>§

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 Deref for OwnedReadWriteMmap

Source§

type Target = ReadWriteMmap<'static>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for OwnedReadWriteMmap

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Send for OwnedReadWriteMmap

Source§

impl Sync for OwnedReadWriteMmap

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.