Skip to main content

Mmap

Struct Mmap 

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

A read-only, private memory map of an open file.

The static-delta reader maps a decompressed part or source object that was spilled to a temp file, so random access (splice offsets, bspatch source seeks) costs address space and demand-paged file cache rather than resident heap. The mapping is never written and keeps the underlying pages alive on its own, so the caller may drop the file descriptor once the map exists.

A mapping must not extend past the end of its file: reading a mapped page with no file bytes behind it raises SIGBUS, which no safe API may expose. Mmap::read_only therefore measures the file itself and rejects an over-long request, and Mmap::as_slice is sound for the map’s whole lifetime as long as nothing truncates the file underneath it. The static-delta reader maps only anonymous temp files it alone holds, so no other writer can shrink one.

Implementations§

Source§

impl Mmap

Source

pub fn read_only(fd: impl AsFd, len: usize) -> Result<Mmap>

Map the first len bytes of fd read-only.

len must be nonzero and must not exceed the file’s size. A zero length returns EINVAL from mmap, and a length past the end of the file returns EINVAL from the size check below, so a map that would fault on read cannot be built.

Source

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

The mapped bytes.

Source

pub fn len(&self) -> usize

The mapped length in bytes.

Source

pub fn is_empty(&self) -> bool

Whether the map covers zero bytes. Always false in practice, since callers map only when the blob exceeds the heap threshold.

Trait Implementations§

Source§

impl Debug for Mmap

Source§

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

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

impl Drop for Mmap

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 Mmap

Source§

impl Sync for Mmap

Auto Trait Implementations§

§

impl Freeze for Mmap

§

impl RefUnwindSafe for Mmap

§

impl Unpin for Mmap

§

impl UnsafeUnpin for Mmap

§

impl UnwindSafe for Mmap

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

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.