pub trait BlobStore:
Send
+ Sync
+ 'static {
// Required methods
fn load(&self, index_name: &str, file_name: &str) -> Result<Vec<u8>, Error>;
fn save(
&self,
index_name: &str,
file_name: &str,
data: &[u8],
) -> Result<(), Error>;
fn delete(&self, index_name: &str, file_name: &str) -> Result<(), Error>;
fn exists(&self, index_name: &str, file_name: &str) -> Result<bool, Error>;
fn list(&self, index_name: &str) -> Result<Vec<String>, Error>;
// Provided methods
fn blob_len(
&self,
_index_name: &str,
_file_name: &str,
) -> Result<Option<u64>, Error> { ... }
fn load_range(
&self,
_index_name: &str,
_file_name: &str,
_range: Range<u64>,
) -> Result<Option<Vec<u8>>, Error> { ... }
}Expand description
Trait for blob storage backends.
Each blob is identified by (index_name, file_name).
index_name: identifies which index (e.g. “Product”, “Article_Index”)file_name: identifies which file within the index (e.g. “meta.json”, “{uuid}.idx”)
Required Methods§
Sourcefn load(&self, index_name: &str, file_name: &str) -> Result<Vec<u8>, Error>
fn load(&self, index_name: &str, file_name: &str) -> Result<Vec<u8>, Error>
Load a blob. Returns NotFound if it doesn’t exist.
Sourcefn save(
&self,
index_name: &str,
file_name: &str,
data: &[u8],
) -> Result<(), Error>
fn save( &self, index_name: &str, file_name: &str, data: &[u8], ) -> Result<(), Error>
Save a blob (create or overwrite).
Sourcefn delete(&self, index_name: &str, file_name: &str) -> Result<(), Error>
fn delete(&self, index_name: &str, file_name: &str) -> Result<(), Error>
Delete a blob. Returns Ok(()) even if the blob didn’t exist.
Provided Methods§
Sourcefn blob_len(
&self,
_index_name: &str,
_file_name: &str,
) -> Result<Option<u64>, Error>
fn blob_len( &self, _index_name: &str, _file_name: &str, ) -> Result<Option<u64>, Error>
Size of a blob in bytes WITHOUT loading it, when the backend can
answer cheaply (LENGTH(_data) in SQL, HEAD on S3…). Ok(None) —
the default — means “unknown”: lazy consumers then fall back to
materialising the file on first open instead of first byte read.
Sourcefn load_range(
&self,
_index_name: &str,
_file_name: &str,
_range: Range<u64>,
) -> Result<Option<Vec<u8>>, Error>
fn load_range( &self, _index_name: &str, _file_name: &str, _range: Range<u64>, ) -> Result<Option<Vec<u8>>, Error>
Read a byte range of a blob without loading it whole, when the
backend can (SUBSTRING(_data FROM … FOR …) in SQL, ranged GET on
S3…). Ok(None) — the default — means “unsupported”: lazy consumers
then materialise the whole blob instead. Out-of-bounds ranges are the
caller’s bug; backends may truncate or error.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T> BlobStore for Arc<T>
Every method forwards, so Arc<dyn BlobStore> (and Arc<Concrete>) can
be used directly wherever an S: BlobStore is expected — e.g.
BlobShardStorage<Arc<dyn BlobStore>> — without a hand-written bridge.
impl<T> BlobStore for Arc<T>
Every method forwards, so Arc<dyn BlobStore> (and Arc<Concrete>) can
be used directly wherever an S: BlobStore is expected — e.g.
BlobShardStorage<Arc<dyn BlobStore>> — without a hand-written bridge.