Skip to main content

SharedFileMapping

Struct SharedFileMapping 

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

A retained mapping, without a second file descriptor or borrowed Rust slices. Mapping ownership may move between threads; byte access requires external exclusion, extent validation and memory barriers at the lock boundary.

Implementations§

Source§

impl SharedFileMapping

Source

pub fn new(file: &File, length: usize) -> Result<Self>

Map an existing prefix, reserving sparse holes before writable access. The caller must serialize this operation with file writes and resizing. The existing file bytes and length are preserved, as is its seek position. Unsupported filesystems or allocation failures should use positioned I/O.

Source

pub fn mapped_len(&self) -> usize

Source

pub fn contains(&self, offset: u64, length: usize) -> bool

Source

pub unsafe fn read(&self, offset: u64, bytes: &mut [u8]) -> bool

Copy a mapped range, returning false if it is outside this mapping.

§Safety

The underlying file must still cover the mapped extent. Exclude writes and resizing in every process for the complete copy, with an acquire barrier after taking the external lock. The destination must not alias the mapping. No reference into the mapped memory escapes this call.

Source

pub unsafe fn write(&self, offset: u64, bytes: &[u8]) -> bool

Replace a mapped range, returning false if it is outside this mapping.

§Safety

The underlying file must still cover the reserved mapped extent. Exclude all other access and resizing until the copy completes, then issue a release barrier before unlocking. The source must not alias the mapping. This publishes coordination bytes; it does not provide crash durability.

Source

pub unsafe fn write_published( &self, offset: u64, bytes: &[u8], state: usize, pending: u8, ) -> bool

Replace a record while publishing its state byte last. An interrupted copy leaves pending, so a peer never decodes a partially written record. Returns false without mutation when either range is invalid.

§Safety

The exclusion, extent and source requirements of write apply. pending must describe a valid unpublished record in the caller’s format, regardless of its remaining bytes. Its state byte must be independently writable.

Trait Implementations§

Source§

impl Drop for SharedFileMapping

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for SharedFileMapping

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.