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§
Sourcefn put(&self, bytes: &[u8]) -> Result<Digest, StoreError>
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.
Sourcefn get(&self, digest: &Digest) -> Result<Option<Vec<u8>>, StoreError>
fn get(&self, digest: &Digest) -> Result<Option<Vec<u8>>, StoreError>
The bytes, if they are here.
Sourcefn bind(
&self,
name: &str,
digest: &Digest,
meta: Meta,
) -> Result<(), StoreError>
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.
Sourcefn claim(
&self,
name: &str,
digest: &Digest,
meta: Meta,
) -> Result<bool, StoreError>
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.
Provided Methods§
Sourcefn resolve_many(&self, names: &[&str]) -> Result<Vec<Option<Bound>>, StoreError>
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.