Skip to main content

Store

Trait Store 

Source
pub trait Store: Send + Sync {
    // Required methods
    fn put(&self, bytes: &[u8]) -> Result<Digest, StoreError>;
    fn get(&self, digest: &Digest) -> Result<Option<Vec<u8>>, StoreError>;
    fn bind(
        &self,
        name: &str,
        digest: &Digest,
        meta: Meta,
    ) -> Result<(), StoreError>;
    fn claim(
        &self,
        name: &str,
        digest: &Digest,
        meta: Meta,
    ) -> Result<bool, StoreError>;
    fn resolve(&self, name: &str) -> Result<Option<Bound>, StoreError>;
    fn bound(&self) -> Result<Vec<Bound>, StoreError>;

    // Provided methods
    fn resolve_many(
        &self,
        names: &[&str],
    ) -> Result<Vec<Option<Bound>>, StoreError> { ... }
    fn get_many(
        &self,
        digests: &[&Digest],
    ) -> Result<Vec<Option<Vec<u8>>>, StoreError> { ... }
}
Expand description

Keeps bytes by their content, and names that point at them.

Required Methods§

Source

fn put(&self, bytes: &[u8]) -> Result<Digest, StoreError>

Saves these bytes. Saving the same ones twice is the same as saving them once — that is what content addressing is for.

Source

fn get(&self, digest: &Digest) -> Result<Option<Vec<u8>>, StoreError>

The bytes, if they are here.

Source

fn bind( &self, name: &str, digest: &Digest, meta: Meta, ) -> Result<(), StoreError>

Points a name at some bytes, with what you want to remember about it.

Binding the same name again replaces it: a name is the question, and the answer can be refreshed — which is what .overwrite() will do.

Source

fn claim( &self, name: &str, digest: &Digest, meta: Meta, ) -> Result<bool, StoreError>

Points a name at some bytes only if nobody has, and says whether it did. This is how work gets handed out.

Not resolve then bind: between the two somebody else does the same, and two machines train the same round while nobody trains the next. Hence on the trait with no default — one written out of the other two would be a race with a doc comment on it.

Source

fn resolve(&self, name: &str) -> Result<Option<Bound>, StoreError>

What that name points at, if anything.

Source

fn bound(&self) -> Result<Vec<Bound>, StoreError>

Everything bound here. A scan, and that is the point: the records are the truth, and an index that answers faster is built from them and thrown away.

Provided Methods§

Source

fn resolve_many(&self, names: &[&str]) -> Result<Vec<Option<Bound>>, StoreError>

The same for many at once, in the order they were asked. In the trait from the first day: a cache that works item by item asks thousands at a time, which against a remote store is thousands of round trips unless it is one call. The default is the loop.

Source

fn get_many( &self, digests: &[&Digest], ) -> Result<Vec<Option<Vec<u8>>>, StoreError>

The same for the bytes.

Implementors§