Skip to main content

BlobStore

Trait BlobStore 

Source
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§

Source

fn load(&self, index_name: &str, file_name: &str) -> Result<Vec<u8>, Error>

Load a blob. Returns NotFound if it doesn’t exist.

Source

fn save( &self, index_name: &str, file_name: &str, data: &[u8], ) -> Result<(), Error>

Save a blob (create or overwrite).

Source

fn delete(&self, index_name: &str, file_name: &str) -> Result<(), Error>

Delete a blob. Returns Ok(()) even if the blob didn’t exist.

Source

fn exists(&self, index_name: &str, file_name: &str) -> Result<bool, Error>

Check if a blob exists.

Source

fn list(&self, index_name: &str) -> Result<Vec<String>, Error>

List all file names for a given index.

Provided Methods§

Source

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.

Source

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>
where T: BlobStore + ?Sized,

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.

Source§

fn load(&self, index_name: &str, file_name: &str) -> Result<Vec<u8>, Error>

Source§

fn save( &self, index_name: &str, file_name: &str, data: &[u8], ) -> Result<(), Error>

Source§

fn delete(&self, index_name: &str, file_name: &str) -> Result<(), Error>

Source§

fn exists(&self, index_name: &str, file_name: &str) -> Result<bool, Error>

Source§

fn list(&self, index_name: &str) -> Result<Vec<String>, Error>

Source§

fn blob_len( &self, index_name: &str, file_name: &str, ) -> Result<Option<u64>, Error>

Source§

fn load_range( &self, index_name: &str, file_name: &str, range: Range<u64>, ) -> Result<Option<Vec<u8>>, Error>

Implementors§