Struct fmmap::raw::MemoryMmapFile
source · 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§
source§impl MemoryMmapFile
impl MemoryMmapFile
sourcepub fn new<P: AsRef<Path>>(path: P, data: Bytes) -> Self
pub fn new<P: AsRef<Path>>(path: P, data: Bytes) -> Self
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());
sourcepub fn from_vec<P: AsRef<Path>>(path: P, src: Vec<u8>) -> Self
pub fn from_vec<P: AsRef<Path>>(path: P, src: Vec<u8>) -> Self
Create a MemoryMmapFile from Vec
Examples
use fmmap::raw::MemoryMmapFile;
let data = (0..=255u8).collect::<Vec<_>>();
MemoryMmapFile::from_vec("foo.mem", data);
sourcepub fn from_string<P: AsRef<Path>>(path: P, src: String) -> Self
pub fn from_string<P: AsRef<Path>>(path: P, src: String) -> Self
Create a MemoryMmapFile from String
Examples
use fmmap::raw::MemoryMmapFile;
let data: &'static str = "some data...";
MemoryMmapFile::from_string("foo.mem", data.to_string());
sourcepub fn from_slice<P: AsRef<Path>>(path: P, src: &'static [u8]) -> Self
pub fn from_slice<P: AsRef<Path>>(path: P, src: &'static [u8]) -> Self
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);
sourcepub fn from_str<P: AsRef<Path>>(path: P, src: &'static str) -> Self
pub fn from_str<P: AsRef<Path>>(path: P, src: &'static str) -> Self
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);
sourcepub fn copy_from_slice<P: AsRef<Path>>(path: P, src: &[u8]) -> Self
pub fn copy_from_slice<P: AsRef<Path>>(path: P, src: &[u8]) -> Self
Create a MemoryMmapFile by copy from slice
Examples
use fmmap::raw::MemoryMmapFile;
MemoryMmapFile::copy_from_slice("foo.mem", "some data...".as_bytes());
sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> 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§
source§impl Clone for MemoryMmapFile
impl Clone for MemoryMmapFile
source§fn clone(&self) -> MemoryMmapFile
fn clone(&self) -> MemoryMmapFile
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl From<MemoryMmapFile> for MmapFile
impl From<MemoryMmapFile> for MmapFile
source§fn from(file: MemoryMmapFile) -> Self
fn from(file: MemoryMmapFile) -> Self
Converts to this type from the input type.
source§impl MmapFileExt for MemoryMmapFile
impl MmapFileExt for MemoryMmapFile
source§fn lock_exclusive(&self) -> Result<()>
fn lock_exclusive(&self) -> Result<()>
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
source§fn try_lock_exclusive(&self) -> Result<()>
fn try_lock_exclusive(&self) -> Result<()>
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
source§fn slice(&self, offset: usize, sz: usize) -> &[u8] ⓘ
fn slice(&self, offset: usize, sz: usize) -> &[u8] ⓘ
slice returns data starting from offset off of size sz. Read more
source§fn bytes(&self, offset: usize, sz: usize) -> Result<&[u8]>
fn bytes(&self, offset: usize, sz: usize) -> Result<&[u8]>
bytes returns data starting from offset off of size sz. Read more
source§fn path_lossy(&self) -> Cow<'_, str>
fn path_lossy(&self) -> Cow<'_, str>
Returns the path lossy string of the inner file.
source§fn path_string(&self) -> String
fn path_string(&self) -> String
Returns the path string of the inner file.
source§fn copy_all_to_vec(&self) -> Vec<u8>
fn copy_all_to_vec(&self) -> Vec<u8>
Copy the content of the mmap file to Vec
source§fn copy_range_to_vec(&self, offset: usize, len: usize) -> Vec<u8>
fn copy_range_to_vec(&self, offset: usize, len: usize) -> Vec<u8>
Copy a range of content of the mmap file to Vec
source§fn write_all_to_new_file<P: AsRef<Path>>(&self, new_file_path: P) -> Result<()>
fn write_all_to_new_file<P: AsRef<Path>>(&self, new_file_path: P) -> Result<()>
Write the content of the mmap file to a new file.
source§fn write_range_to_new_file<P: AsRef<Path>>(
&self,
new_file_path: P,
offset: usize,
len: usize
) -> Result<()>
fn write_range_to_new_file<P: AsRef<Path>>( &self, new_file_path: P, offset: usize, len: usize ) -> Result<()>
Write a range of content of the mmap file to new file.
source§fn reader(&self, offset: usize) -> Result<MmapFileReader<'_>>
fn reader(&self, offset: usize) -> Result<MmapFileReader<'_>>
Returns a
MmapFileReader
which helps read data from mmap like a normal File. Read moresource§fn range_reader(&self, offset: usize, len: usize) -> Result<MmapFileReader<'_>>
fn range_reader(&self, offset: usize, len: usize) -> Result<MmapFileReader<'_>>
Returns a
MmapFileReader
base on the given offset
and len
, which helps read data from mmap like a normal File. Read moresource§fn read(&self, dst: &mut [u8], offset: usize) -> usize
fn read(&self, dst: &mut [u8], offset: usize) -> usize
Read bytes to the dst buf from the offset, returns how many bytes read.
source§fn read_exact(&self, dst: &mut [u8], offset: usize) -> Result<()>
fn read_exact(&self, dst: &mut [u8], offset: usize) -> Result<()>
Read the exact number of bytes required to fill buf.
source§fn read_i16(&self, offset: usize) -> Result<i16>
fn read_i16(&self, offset: usize) -> Result<i16>
Read a signed 16 bit integer from offset in big-endian byte order.
source§fn read_i16_le(&self, offset: usize) -> Result<i16>
fn read_i16_le(&self, offset: usize) -> Result<i16>
Read a signed 16 bit integer from offset in little-endian byte order.
source§fn read_isize(&self, offset: usize) -> Result<isize>
fn read_isize(&self, offset: usize) -> Result<isize>
Read a signed integer from offset in big-endian byte order.
source§fn read_isize_le(&self, offset: usize) -> Result<isize>
fn read_isize_le(&self, offset: usize) -> Result<isize>
Read a signed integer from offset in little-endian byte order.
source§fn read_i32(&self, offset: usize) -> Result<i32>
fn read_i32(&self, offset: usize) -> Result<i32>
Read a signed 32 bit integer from offset in big-endian byte order.
source§fn read_i32_le(&self, offset: usize) -> Result<i32>
fn read_i32_le(&self, offset: usize) -> Result<i32>
Read a signed 32 bit integer from offset in little-endian byte order.
source§fn read_i64(&self, offset: usize) -> Result<i64>
fn read_i64(&self, offset: usize) -> Result<i64>
Read a signed 64 bit integer from offset in big-endian byte order.
source§fn read_i64_le(&self, offset: usize) -> Result<i64>
fn read_i64_le(&self, offset: usize) -> Result<i64>
Read a signed 64 bit integer from offset in little-endian byte order.
source§fn read_i128(&self, offset: usize) -> Result<i128>
fn read_i128(&self, offset: usize) -> Result<i128>
Read a signed 128 bit integer from offset in big-endian byte order.
source§fn read_i128_le(&self, offset: usize) -> Result<i128>
fn read_i128_le(&self, offset: usize) -> Result<i128>
Read a signed 128 bit integer from offset in little-endian byte order.
source§fn read_u16(&self, offset: usize) -> Result<u16>
fn read_u16(&self, offset: usize) -> Result<u16>
Read an unsigned 16 bit integer from offset in big-endian.
source§fn read_u16_le(&self, offset: usize) -> Result<u16>
fn read_u16_le(&self, offset: usize) -> Result<u16>
Read an unsigned 16 bit integer from offset in little-endian.
source§fn read_usize(&self, offset: usize) -> Result<usize>
fn read_usize(&self, offset: usize) -> Result<usize>
Read an unsigned integer from offset in big-endian byte order.
source§fn read_usize_le(&self, offset: usize) -> Result<usize>
fn read_usize_le(&self, offset: usize) -> Result<usize>
Read an unsigned integer from offset in little-endian byte order.
source§fn read_u32(&self, offset: usize) -> Result<u32>
fn read_u32(&self, offset: usize) -> Result<u32>
Read an unsigned 32 bit integer from offset in big-endian.
source§fn read_u32_le(&self, offset: usize) -> Result<u32>
fn read_u32_le(&self, offset: usize) -> Result<u32>
Read an unsigned 32 bit integer from offset in little-endian.
source§fn read_u64(&self, offset: usize) -> Result<u64>
fn read_u64(&self, offset: usize) -> Result<u64>
Read an unsigned 64 bit integer from offset in big-endian.
source§fn read_u64_le(&self, offset: usize) -> Result<u64>
fn read_u64_le(&self, offset: usize) -> Result<u64>
Read an unsigned 64 bit integer from offset in little-endian.
source§fn read_u128(&self, offset: usize) -> Result<u128>
fn read_u128(&self, offset: usize) -> Result<u128>
Read an unsigned 128 bit integer from offset in big-endian.
source§fn read_u128_le(&self, offset: usize) -> Result<u128>
fn read_u128_le(&self, offset: usize) -> Result<u128>
Read an unsigned 128 bit integer from offset in little-endian.
source§fn read_f32(&self, offset: usize) -> Result<f32>
fn read_f32(&self, offset: usize) -> Result<f32>
Read an IEEE754 single-precision (4 bytes) floating point number from
offset in big-endian byte order.
source§fn read_f32_le(&self, offset: usize) -> Result<f32>
fn read_f32_le(&self, offset: usize) -> Result<f32>
Read an IEEE754 single-precision (4 bytes) floating point number from
offset in little-endian byte order.
source§impl PartialEq<MemoryMmapFile> for MemoryMmapFile
impl PartialEq<MemoryMmapFile> for MemoryMmapFile
source§fn eq(&self, other: &MemoryMmapFile) -> bool
fn eq(&self, other: &MemoryMmapFile) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Eq for MemoryMmapFile
impl StructuralEq for MemoryMmapFile
impl StructuralPartialEq for MemoryMmapFile
Auto Trait Implementations§
impl RefUnwindSafe for MemoryMmapFile
impl Send for MemoryMmapFile
impl Sync for MemoryMmapFile
impl Unpin for MemoryMmapFile
impl UnwindSafe for MemoryMmapFile
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more