[−][src]Struct mmap_storage::anonim::Storage
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
Methods
impl Storage
[src]
pub fn new(size: usize) -> Result<Self>
[src]
Creates storage with specified size.
pub fn as_slice(&self) -> &[u8]
[src]
Returns slice with view on written data.
pub fn as_mut_slice(&mut self) -> &mut [u8]
[src]
Returns slice with view on written data.
pub fn capacity(&self) -> usize
[src]
Returns overall size of storage(including extra space).
pub fn flush_async(&self) -> Result<()>
[src]
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.
pub fn flush_sync(&self) -> Result<()>
[src]
Synchronously flushes outstanding memory map modifications to disk.
pub fn extend_from_slice(&mut self, data: &[u8]) -> Result<()>
[src]
Appends data to storage
Note that it resizes storage if needed. Therefore error can happen.
pub fn copy_from_slice(&mut self, data: &[u8])
[src]
Copies data from slice into storage.
Function panics if data has greater len.
Note: It copies data up to storage capacity.
pub fn resize(&mut self, new_size: usize) -> Result<()>
[src]
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.
pub fn clear(&mut self)
[src]
Clears content of storage.
Note that it doesn't affect capacity in any way.
pub fn to_vec(&self) -> Vec<u8>
[src]
Creates Vec
from content of storage.
Trait Implementations
impl Default for Storage
[src]
impl Write for Storage
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn write_all(&mut self, buf: &[u8]) -> Result<()>
[src]
fn flush(&mut self) -> Result<()>
[src]
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>
1.36.0[src]
Like write
, except that it writes from a slice of buffers. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Creates a "by reference" adaptor for this instance of Write
. Read more
Auto Trait Implementations
impl Send for Storage
impl Unpin for Storage
impl Sync for Storage
impl UnwindSafe for Storage
impl RefUnwindSafe for Storage
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,