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§
Sourceasync unsafe fn pure_readv(
&self,
bufv: IoVectorMut<'_>,
offset: u64,
) -> Result<()>
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.
Sourceasync unsafe fn pure_writev(
&self,
bufv: IoVector<'_>,
offset: u64,
) -> Result<()>
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.
Sourceasync fn flush(&self) -> Result<()>
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.
Sourceasync fn sync(&self) -> Result<()>
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.
Sourceasync unsafe fn invalidate_cache(&self) -> Result<()>
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.
Sourcefn get_storage_helper(&self) -> &CommonStorageHelper
fn get_storage_helper(&self) -> &CommonStorageHelper
Return the storage helper object (used by the StorageExt
implementation).
Provided Methods§
Sourceasync fn open(_opts: StorageOpenOptions) -> Result<Self>
async fn open(_opts: StorageOpenOptions) -> Result<Self>
Open a storage object.
Different storage implementations may require different options.
Sourcefn open_sync(opts: StorageOpenOptions) -> Result<Self>
fn open_sync(opts: StorageOpenOptions) -> Result<Self>
Synchronous wrapper around Storage::open()
.
Sourceasync fn create_open(_opts: StorageCreateOptions) -> Result<Self>
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.
Sourceasync fn create(opts: StorageCreateOptions) -> Result<()>
async fn create(opts: StorageCreateOptions) -> Result<()>
Create a storage object.
Different storage implementations may require different options.
Sourcefn zero_align(&self) -> usize
fn zero_align(&self) -> usize
Minimum required alignment for zero writes.
Sourcefn discard_align(&self) -> usize
fn discard_align(&self) -> usize
Minimum required alignment for effective discards.
Sourcefn resolve_relative_path<P: AsRef<Path>>(&self, _relative: P) -> Result<PathBuf>
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()
.
Sourcefn get_filename(&self) -> Option<PathBuf>
fn get_filename(&self) -> Option<PathBuf>
Return a filename, if possible.
Using the filename for StorageOpenOptions::filename()
should open the same storage
object.
Sourceasync unsafe fn pure_write_zeroes(&self, offset: u64, length: u64) -> Result<()>
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.
Sourceasync unsafe fn pure_discard(&self, _offset: u64, _length: u64) -> Result<()>
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.
Sourceasync fn resize(
&self,
_new_size: u64,
_prealloc_mode: PreallocateMode,
) -> Result<()>
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.