Trait Storage

Source
pub trait Storage:
    Debug
    + Display
    + Send
    + Sized
    + Sync {
Show 20 methods // Required methods fn size(&self) -> Result<u64>; async unsafe fn pure_readv( &self, bufv: IoVectorMut<'_>, offset: u64, ) -> Result<()>; async unsafe fn pure_writev( &self, bufv: IoVector<'_>, offset: u64, ) -> Result<()>; async fn flush(&self) -> Result<()>; async fn sync(&self) -> Result<()>; async unsafe fn invalidate_cache(&self) -> Result<()>; fn get_storage_helper(&self) -> &CommonStorageHelper; // Provided methods async fn open(_opts: StorageOpenOptions) -> Result<Self> { ... } fn open_sync(opts: StorageOpenOptions) -> Result<Self> { ... } async fn create_open(_opts: StorageCreateOptions) -> Result<Self> { ... } async fn create(opts: StorageCreateOptions) -> Result<()> { ... } fn mem_align(&self) -> usize { ... } fn req_align(&self) -> usize { ... } fn zero_align(&self) -> usize { ... } fn discard_align(&self) -> usize { ... } fn resolve_relative_path<P: AsRef<Path>>( &self, _relative: P, ) -> Result<PathBuf> { ... } fn get_filename(&self) -> Option<PathBuf> { ... } async unsafe fn pure_write_zeroes( &self, offset: u64, length: u64, ) -> Result<()> { ... } async unsafe fn pure_discard( &self, _offset: u64, _length: u64, ) -> Result<()> { ... } async fn resize( &self, _new_size: u64, _prealloc_mode: PreallocateMode, ) -> Result<()> { ... }
}
Expand description

Implementation for storage objects.

Required Methods§

Source

fn size(&self) -> Result<u64>

Storage object length.

Source

async unsafe fn pure_readv( &self, bufv: IoVectorMut<'_>, offset: u64, ) -> Result<()>

Read data at offset into bufv.

Reads until bufv is filled completely, i.e. will not do short reads. When reaching the end of file, the rest of bufv is filled with 0.

§Safety

This is a pure read from storage. The request must be fully aligned to Self::mem_align() and Self::req_align(), and safeguards we want to implement for safe concurrent access may not be available.

Use StorageExt::readv() instead.

Source

async unsafe fn pure_writev( &self, bufv: IoVector<'_>, offset: u64, ) -> Result<()>

Write data from bufv to offset.

Writes all data from bufv, i.e. will not do short writes. When reaching the end of file, grow it as necessary so that the new end of file will be at offset + bufv.len().

If growing is not possible, writes beyond the end of file (even if only partially) should fail.

§Safety

This is a pure write to storage. The request must be fully aligned to Self::mem_align() and Self::req_align(), and safeguards we want to implement for safe concurrent access may not be available.

Use StorageExt::writev() instead.

Source

async fn flush(&self) -> Result<()>

Flush internal buffers.

Does not necessarily sync those buffers to disk. When using flush(), consider whether you want to call sync() afterwards.

Note that this will not drop the buffers, so they may still be used to serve later accesses. Use Storage::invalidate_cache() to drop all buffers.

Source

async fn sync(&self) -> Result<()>

Sync data already written to the storage hardware.

This does not necessarily include flushing internal buffers, i.e. flush. When using sync(), consider whether you want to call flush() before it.

Source

async unsafe fn invalidate_cache(&self) -> Result<()>

Drop internal buffers.

This drops all internal buffers, but does not flush them! All cached data is reloaded on subsequent accesses.

§Safety

Not flushing internal buffers may cause corruption. You must ensure the underlying storage state is consistent.

Source

fn get_storage_helper(&self) -> &CommonStorageHelper

Return the storage helper object (used by the StorageExt implementation).

Provided Methods§

Source

async fn open(_opts: StorageOpenOptions) -> Result<Self>

Open a storage object.

Different storage implementations may require different options.

Source

fn open_sync(opts: StorageOpenOptions) -> Result<Self>

Synchronous wrapper around Storage::open().

Source

async fn create_open(_opts: StorageCreateOptions) -> Result<Self>

Create a storage object and open it.

Different storage implementations may require different options.

Note that newly created storage objects are always opened as writable.

Source

async fn create(opts: StorageCreateOptions) -> Result<()>

Create a storage object.

Different storage implementations may require different options.

Source

fn mem_align(&self) -> usize

Minimum required alignment for memory buffers.

Source

fn req_align(&self) -> usize

Minimum required alignment for offsets and lengths.

Source

fn zero_align(&self) -> usize

Minimum required alignment for zero writes.

Source

fn discard_align(&self) -> usize

Minimum required alignment for effective discards.

Source

fn resolve_relative_path<P: AsRef<Path>>(&self, _relative: P) -> Result<PathBuf>

Resolve the given path relative to this storage object.

relative need not really be a relative path; it is up to the storage driver to check whether it is an absolute path that does not need to be changed, or a relative path that needs to be resolved.

Must not return a relative path.

The returned PathBuf should be usable with StorageOpenOptions::filename().

Source

fn get_filename(&self) -> Option<PathBuf>

Return a filename, if possible.

Using the filename for StorageOpenOptions::filename() should open the same storage object.

Source

async unsafe fn pure_write_zeroes(&self, offset: u64, length: u64) -> Result<()>

Ensure the given range reads back as zeroes.

The default implementation writes actual zeroes as data, which is inefficient. Storage drivers should override it with a more efficient implementation.

§Safety

This is a pure write to storage. The request must be fully aligned to Self::zero_align(), and safeguards we want to implement for safe concurrent access may not be available.

Use StorageExt::write_zeroes() instead.

Source

async unsafe fn pure_discard(&self, _offset: u64, _length: u64) -> Result<()>

Discard the given range, with undefined contents when read back.

Tell the storage layer this range is no longer needed and need not be backed by actual storage. When read back, the data read will be undefined, i.e. not necessarily zeroes.

No-op implementations therefore explicitly fulfill the interface contract.

§Safety

This is a pure write to storage. The request must be fully aligned to Self::discard_align(), and safeguards we want to implement for safe concurrent access may not be available.

Use StorageExt::discard() instead.

Source

async fn resize( &self, _new_size: u64, _prealloc_mode: PreallocateMode, ) -> Result<()>

Resize to the given size.

Set the size of this storage object to new_size. If new_size is smaller than the current size, ignore prealloc_mode and discard the data after new_size.

If new_size is larger than the current size, prealloc_mode determines whether and how the new range should be allocated; it is possible some preallocation modes are not supported, in which case an std::io::ErrorKind::Unsupported is returned.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Storage for Box<dyn DynStorage>

Source§

async fn open(opts: StorageOpenOptions) -> Result<Self>

Source§

async fn create_open(opts: StorageCreateOptions) -> Result<Self>

Source§

fn mem_align(&self) -> usize

Source§

fn req_align(&self) -> usize

Source§

fn zero_align(&self) -> usize

Source§

fn discard_align(&self) -> usize

Source§

fn size(&self) -> Result<u64>

Source§

fn resolve_relative_path<P: AsRef<Path>>(&self, relative: P) -> Result<PathBuf>

Source§

fn get_filename(&self) -> Option<PathBuf>

Source§

async unsafe fn pure_readv( &self, bufv: IoVectorMut<'_>, offset: u64, ) -> Result<()>

Source§

async unsafe fn pure_writev( &self, bufv: IoVector<'_>, offset: u64, ) -> Result<()>

Source§

async unsafe fn pure_write_zeroes(&self, offset: u64, length: u64) -> Result<()>

Source§

async unsafe fn pure_discard(&self, offset: u64, length: u64) -> Result<()>

Source§

async fn flush(&self) -> Result<()>

Source§

async fn sync(&self) -> Result<()>

Source§

async unsafe fn invalidate_cache(&self) -> Result<()>

Source§

fn get_storage_helper(&self) -> &CommonStorageHelper

Source§

async fn resize( &self, new_size: u64, prealloc_mode: PreallocateMode, ) -> Result<()>

Source§

impl Storage for Arc<dyn DynStorage>

Source§

async fn open(opts: StorageOpenOptions) -> Result<Self>

Source§

async fn create_open(opts: StorageCreateOptions) -> Result<Self>

Source§

fn mem_align(&self) -> usize

Source§

fn req_align(&self) -> usize

Source§

fn zero_align(&self) -> usize

Source§

fn discard_align(&self) -> usize

Source§

fn size(&self) -> Result<u64>

Source§

fn resolve_relative_path<P: AsRef<Path>>(&self, relative: P) -> Result<PathBuf>

Source§

fn get_filename(&self) -> Option<PathBuf>

Source§

async unsafe fn pure_readv( &self, bufv: IoVectorMut<'_>, offset: u64, ) -> Result<()>

Source§

async unsafe fn pure_writev( &self, bufv: IoVector<'_>, offset: u64, ) -> Result<()>

Source§

async unsafe fn pure_write_zeroes(&self, offset: u64, length: u64) -> Result<()>

Source§

async unsafe fn pure_discard(&self, offset: u64, length: u64) -> Result<()>

Source§

async fn flush(&self) -> Result<()>

Source§

async fn sync(&self) -> Result<()>

Source§

async unsafe fn invalidate_cache(&self) -> Result<()>

Source§

fn get_storage_helper(&self) -> &CommonStorageHelper

Source§

async fn resize( &self, new_size: u64, prealloc_mode: PreallocateMode, ) -> Result<()>

Source§

impl<S: Storage> Storage for &S

Source§

fn mem_align(&self) -> usize

Source§

fn req_align(&self) -> usize

Source§

fn zero_align(&self) -> usize

Source§

fn discard_align(&self) -> usize

Source§

fn size(&self) -> Result<u64>

Source§

fn resolve_relative_path<P: AsRef<Path>>(&self, relative: P) -> Result<PathBuf>

Source§

fn get_filename(&self) -> Option<PathBuf>

Source§

async unsafe fn pure_readv( &self, bufv: IoVectorMut<'_>, offset: u64, ) -> Result<()>

Source§

async unsafe fn pure_writev( &self, bufv: IoVector<'_>, offset: u64, ) -> Result<()>

Source§

async unsafe fn pure_write_zeroes(&self, offset: u64, length: u64) -> Result<()>

Source§

async unsafe fn pure_discard(&self, offset: u64, length: u64) -> Result<()>

Source§

async fn flush(&self) -> Result<()>

Source§

async fn sync(&self) -> Result<()>

Source§

async unsafe fn invalidate_cache(&self) -> Result<()>

Source§

fn get_storage_helper(&self) -> &CommonStorageHelper

Source§

async fn resize( &self, new_size: u64, prealloc_mode: PreallocateMode, ) -> Result<()>

Implementors§