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

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

Notes

MemoryMmapFileMut mocks a mmap behaviour, which means when writing to it, it will not auto-grow its size, so if you want to grow the size of the MemoryMmapFileMut, you need to truncate it first.

If you want the auto-grow functionality, please use BytesMut.

Implementations

Create a MemoryMmapFileMut

Examples
use fmmap::raw::MemoryMmapFileMut;

MemoryMmapFileMut::new("foo.mem");

Create a MemoryMmapFileMutwith capacity

Examples
use fmmap::raw::MemoryMmapFileMut;

MemoryMmapFileMut::with_capacity("foo.mem", 1000);

Create a MemoryMmapFileMut from Vec

Examples
use fmmap::raw::MemoryMmapFileMut;

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

Create a MemoryMmapFileMut from String

Examples
use fmmap::raw::MemoryMmapFileMut;

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

Create a MemoryMmapFileMut from static str

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

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

Create a MemoryMmapFileMut by from slice

Examples
use fmmap::raw::MemoryMmapFileMut;

MemoryMmapFileMut::from_slice("foo.mem", "some data...".as_bytes());

Returns the inner mutable bytes

Examples
use bytes::BytesMut;
use fmmap::raw::MemoryMmapFileMut;

let b1 = MemoryMmapFileMut::from_slice("foo.mem", "some data...".as_bytes()).into_bytes_mut();
assert_eq!(b1, BytesMut::from("some data...".as_bytes()));

Returns the inner bytes

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

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

Make the memory mmap file immutable

Examples
use bytes::Bytes;
use fmmap::MmapFileExt;
use fmmap::raw::{MemoryMmapFileMut,MemoryMmapFile};

let b1 = MemoryMmapFileMut::from_string("foo.mem", "some data...".to_string()).freeze();
let b2 = MemoryMmapFile::from_string("foo.mem", "some data...".to_string());
assert!(!b1.is_exec());
assert_eq!(b1.len(), b2.len());
assert_eq!(b1.as_slice(), b2.as_slice());
assert_eq!(b1.path_string(), b2.path_string());

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

Returns the mutable underlying slice of the mmap

Whether mmap is copy on write

Flushes outstanding memory map modifications to disk (if the inner is a real file). Read more

Asynchronously flushes outstanding memory map modifications to disk(if the inner is a real file). Read more

Flushes outstanding memory map modifications in the range to disk(if the inner is a real file). Read more

Asynchronously flushes outstanding memory map modifications in the range to disk(if the inner is a real file). Read more

Truncates the file to the max_size, which will lead to do re-mmap and sync_dir if the inner is a real file. Read more

Remove the underlying file

Close and truncate the underlying file

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

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

Fill 0 to the specific range

Returns a MmapFileWriter base on the given offset, which helps read or write data from mmap like a normal File. Read more

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

Write bytes to the mmap from the offset.

Write the all of bytes in src to the mmap from the offset.

Writes a signed 8 bit integer to mmap from the offset.

Writes a signed 16 bit integer to mmap from the offset in the big-endian byte order.

Writes a signed 16 bit integer to mmap from the offset in the little-endian byte order.

Writes a signed integer to mmap from the offset in the big-endian byte order.

Writes a signed integer to mmap from the offset in the little-endian byte order.

Writes a signed 32 bit integer to mmap from the offset in the big-endian byte order.

Writes a signed 32 bit integer to mmap from the offset in the little-endian byte order.

Writes a signed 64 bit integer to mmap from the offset in the big-endian byte order.

Writes a signed 64 bit integer to mmap from the offset in the little-endian byte order.

Writes a signed 128 bit integer to mmap from the offset in the big-endian byte order.

Writes a signed 128 bit integer to mmap from the offset in the little-endian byte order.

Writes an unsigned 8 bit integer to mmap from the offset.

Writes an unsigned 16 bit integer to mmap from the offset in the big-endian byte order.

Writes an unsigned 16 bit integer to mmap from the offset in the little-endian byte order.

Writes an unsigned integer to mmap from the offset in the big-endian byte order.

Writes an unsigned integer to mmap from the offset in the little-endian byte order.

Writes an unsigned 32 bit integer to mmap from the offset in the big-endian byte order.

Writes an unsigned 32 bit integer to mmap from the offset in the little-endian byte order.

Writes an unsigned 64 bit integer to mmap from the offset in the big-endian byte order.

Writes an unsigned 64 bit integer to mmap from the offset in the little-endian byte order.

Writes an unsigned 128 bit integer to mmap from the offset in the big-endian byte order.

Writes an unsigned 128 bit integer to mmap from the offset in the little-endian byte order.

Writes an IEEE754 single-precision (4 bytes) floating point number to mmap from the offset in big-endian byte order.

Writes an IEEE754 single-precision (4 bytes) floating point number to mmap from the offset in little-endian byte order.

Writes an IEEE754 single-precision (8 bytes) floating point number to mmap from the offset in big-endian byte order.

Writes an IEEE754 single-precision (8 bytes) floating point number to mmap from the offset in little-endian byte order.

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.