pub struct MemoryMmapFile { /* private fields */ }
Available on crate feature sync only.
Expand description

Use Bytes to mock a mmap, which is useful for test and in-memory storage engine.

Implementations

Create a MemoryMmapFile

Examples
use bytes::{BufMut, BytesMut};
use fmmap::raw::MemoryMmapFile;

let mut data = BytesMut::with_capacity(100);
data.put_slice("some data...".as_bytes());
MemoryMmapFile::new("foo.mem", data.freeze());

Create a MemoryMmapFile from Vec

Examples
use fmmap::raw::MemoryMmapFile;

let data = (0..=255u8).collect::<Vec<_>>();
MemoryMmapFile::from_vec("foo.mem", data);

Create a MemoryMmapFile from String

Examples
use fmmap::raw::MemoryMmapFile;

let data: &'static str = "some data...";
MemoryMmapFile::from_string("foo.mem", data.to_string());

Create a MemoryMmapFile from static slice

Examples
use bytes::Bytes;
use fmmap::raw::MemoryMmapFile;

let data: &'static [u8] = "some data...".as_bytes();
MemoryMmapFile::from_slice("foo.mem", data);

Create a MemoryMmapFile from static str

Examples
use bytes::Bytes;
use fmmap::raw::MemoryMmapFile;

let data: &'static str = "some data...";
MemoryMmapFile::from_str("foo.mem", data);

Create a MemoryMmapFile by copy from slice

Examples
use fmmap::raw::MemoryMmapFile;

MemoryMmapFile::copy_from_slice("foo.mem", "some data...".as_bytes());

Returns the inner bytes

Examples
use bytes::Bytes;
use fmmap::raw::MemoryMmapFile;

let b1 = MemoryMmapFile::copy_from_slice("foo.mem", "some data...".as_bytes()).into_bytes();
assert_eq!(b1, Bytes::copy_from_slice("some data...".as_bytes()));

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Converts to this type from the input type.

Returns the current mmap length

Returns the underlying slice of the mmap

Returns the path of the inner file.

Whether the mmap is executable.

Returns the metadata of file metadata Read more

Locks the file for shared usage, blocking if the file is currently locked exclusively. Read more

Locks the file for exclusive usage, blocking if the file is currently locked. Read more

Locks the file for shared usage, or returns a an error if the file is currently locked (see lock_contended_error). Read more

Locks the file for shared usage, or returns a an error if the file is currently locked (see lock_contended_error).Locks the file for shared usage, or returns a an error if the file is currently locked (see lock_contended_error). Read more

Unlocks the file. Read more

Returns the mmap is empty of not.

slice returns data starting from offset off of size sz. Read more

bytes returns data starting from offset off of size sz. Read more

Returns the path buf of the inner file.

Returns the path lossy string of the inner file.

Returns the path string of the inner file.

Copy the content of the mmap file to Vec

Copy a range of content of the mmap file to Vec

Write the content of the mmap file to a new file.

Write a range of content of the mmap file to new file.

Returns a MmapFileReader which helps read data from mmap like a normal File. Read more

Returns a MmapFileReader base on the given offset and len, which helps read data from mmap like a normal File. Read more

Read bytes to the dst buf from the offset, returns how many bytes read.

Read the exact number of bytes required to fill buf.

Read a signed 8 bit integer from offset.

Read a signed 16 bit integer from offset in big-endian byte order.

Read a signed 16 bit integer from offset in little-endian byte order.

Read a signed integer from offset in big-endian byte order.

Read a signed integer from offset in little-endian byte order.

Read a signed 32 bit integer from offset in big-endian byte order.

Read a signed 32 bit integer from offset in little-endian byte order.

Read a signed 64 bit integer from offset in big-endian byte order.

Read a signed 64 bit integer from offset in little-endian byte order.

Read a signed 128 bit integer from offset in big-endian byte order.

Read a signed 128 bit integer from offset in little-endian byte order.

Read an unsigned 8 bit integer from offset.

Read an unsigned 16 bit integer from offset in big-endian.

Read an unsigned 16 bit integer from offset in little-endian.

Read an unsigned integer from offset in big-endian byte order.

Read an unsigned integer from offset in little-endian byte order.

Read an unsigned 32 bit integer from offset in big-endian.

Read an unsigned 32 bit integer from offset in little-endian.

Read an unsigned 64 bit integer from offset in big-endian.

Read an unsigned 64 bit integer from offset in little-endian.

Read an unsigned 128 bit integer from offset in big-endian.

Read an unsigned 128 bit integer from offset in little-endian.

Read an IEEE754 single-precision (4 bytes) floating point number from offset in big-endian byte order. Read more

Read an IEEE754 single-precision (4 bytes) floating point number from offset in little-endian byte order. Read more

Read an IEEE754 single-precision (8 bytes) floating point number from offset in big-endian byte order. Read more

Read an IEEE754 single-precision (8 bytes) floating point number from offset in little-endian byte order. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.