pub struct Storage { /* private fields */ }Expand description
Anonymous memory map backed storage
It provides byte storage over anonymous memory map.
When new data is written the storage may be extended using following strategy:
- If new data is small enough, resize to double size.
- Otherwise resize to new data_size.
If needed you can use resize method to shrink or extend storage.
Unless otherwise stated all methods that modify content of storage doesn’t perform flushes, it is callee’s responsibility to call it when required
Implementations§
Source§impl Storage
impl Storage
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 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.
Sourcepub fn resize(&mut self, new_size: usize) -> Result<()>
pub fn resize(&mut self, new_size: usize) -> Result<()>
Resizes storage by appending or truncating.
As it requires re-create mmap, the error is possible to happen. In case of error, original storage is preserved.
After successfully creating new storage, previous storage content gets copied.
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)