Struct Mmap

Source
pub struct Mmap {
    pub size: u64,
    /* private fields */
}
Expand description

A struct that represents a memory-mapped file.

Fields§

§size: u64

Implementations§

Source§

impl Mmap

Source

pub fn new(path: &Path) -> Result<Self, MmapError>

Creates a new Mmap instance by opening the file at the given path.

§Arguments
  • path - The path to the file to be memory-mapped.
§Returns

A Result containing the Mmap instance or a MmapError if the operation fails.

§Errors

This function may return the following errors:

  • ErrFdNotAvail: The file descriptor is not available for mapping.
  • ErrInvalidFd: The file descriptor is invalid.
  • ErrUnaligned: The mapping is not properly aligned.
  • ErrNoMapSupport: The file system does not support memory mapping.
  • ErrNoMem: There is not enough memory available to complete the operation.
  • ErrUnknown(code): An unknown error occurred with the given OS error code.
Source

pub fn append(&mut self, data: &[u8]) -> Result<(), Error>

Appends the given data to the end of the memory-mapped file.

§Arguments
  • data - The data to be appended to the file.
§Returns

A Result containing the unit type (()) or an io::Error if the operation fails.

Source

pub fn append_with<F>(&mut self, len: usize, writer: F) -> Result<(), Error>
where F: FnOnce(&mut [u8]),

Appends data to the end of the memory-mapped file using a custom writer function.

§Arguments
  • len - The length of the data to be appended.
  • writer - A closure that writes the data to the file.
§Returns

A Result containing the unit type (()) or an io::Error if the operation fails.

Source

pub fn overwrite(&self, offset: usize, data: &[u8]) -> Result<(), Error>

Overwrites the data at the specified offset in the memory-mapped file.

§Arguments
  • offset - The offset in the file where the data should be overwritten.
  • data - The data to be written.
§Returns

A Result containing the unit type (()) or an io::Error if the operation fails.

Source

pub fn overwrite_with<F>( &self, offset: usize, len: usize, writer: F, ) -> Result<(), Error>
where F: FnOnce(&mut [u8]),

Overwrites data in the memory-mapped file using a custom writer function.

§Arguments
  • offset - The offset in the file where the data should be overwritten.
  • len - The length of the data to be written.
  • writer - A closure that writes the data to the file.
§Returns

A Result containing the unit type (()) or an io::Error if the operation fails.

Source

pub fn drop_from_tail(&mut self, len: usize) -> Result<(), Error>

Removes the specified amount of data from the end of the memory-mapped file by truncating the file.

§Arguments
  • len - The amount of data to be removed from the end of the file.
§Returns

A Result containing the unit type (()) or an io::Error if the operation fails.

Source

pub fn read(&self, offset: usize, len: usize) -> Result<Vec<u8>, Error>

Reads data from the memory-mapped file at the specified offset.

§Arguments
  • offset - The offset in the file where the data should be read from.
  • buf - The buffer to store the read data.
§Returns

A Result containing the number of bytes read or an io::Error if the operation fails.

Source

pub fn read_with<F>( &self, offset: usize, len: usize, reader: F, ) -> Result<(), Error>
where F: FnOnce(&[u8]),

Reads data from the memory-mapped file at the specified offset using a custom reader function.

§Arguments
  • offset - The offset in the file where the data should be read from.
  • len - The length of the data to be read.
  • reader - A closure that reads the data from the file.
§Returns

A Result containing the number of bytes read or an io::Error if the operation fails.

Auto Trait Implementations§

§

impl Freeze for Mmap

§

impl RefUnwindSafe for Mmap

§

impl !Send for Mmap

§

impl !Sync for Mmap

§

impl Unpin 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 = 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.