pub struct Storage { /* private fields */ }
Expand description
File memory map backed storage.
Attempting to resize storage results in error.
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Creates storage by opening or creating file at the specified location.
If file is newly created it is appended dummy byte.
Sourcepub fn open_exising<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open_exising<P: AsRef<Path>>(path: P) -> Result<Self>
Opens storage, if it doesn’t exist return error.
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns slice with view on written data.
Sourcepub fn flush_async(&self) -> Result<()>
pub fn flush_async(&self) -> Result<()>
Asynchronously flushes outstanding memory map modifications to disk.
This method initiates flushing modified pages to durable storage, but it will not wait for the operation to complete before returning.
Sourcepub fn flush_sync(&self) -> Result<()>
pub fn flush_sync(&self) -> Result<()>
Synchronously flushes outstanding memory map modifications to disk.
Sourcepub fn resize(&mut self, new_size: usize) -> Result<()>
pub fn resize(&mut self, new_size: usize) -> Result<()>
Resizes storage by appending or truncating.
It modifies file size and re-mmaps file. When Attempting to set size to 0, the actual size will become 1.
If current cursor of data becomes out of actual file storage, it is shifted to actual file storage size
Sourcepub fn put_data(&mut self, data: &[u8]) -> Result<()>
pub fn put_data(&mut self, data: &[u8]) -> Result<()>
Resizes map accordingly to data and copies it.
Convenience method to map buffer to file.
Sourcepub fn extend_from_slice(&mut self, data: &[u8]) -> Result<()>
pub fn extend_from_slice(&mut self, data: &[u8]) -> Result<()>
Appends data to storage
Note that it resizes storage if needed. Therefore error can happen.
Sourcepub fn copy_from_slice(&mut self, data: &[u8])
pub fn copy_from_slice(&mut self, data: &[u8])
Copies data from slice into storage.
Function panics if data has greater len.
Note: It copies data up to storage capacity.
Trait Implementations§
Source§impl Write for Storage
impl Write for Storage
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)