pub trait ObjectStore:
Send
+ Sync
+ Debug {
// Required methods
fn hash_algo(&self) -> HashAlgo;
fn read(&self, oid: &ObjectId) -> Result<Option<Object>>;
fn read_info(&self, oid: &ObjectId) -> Result<Option<ObjectInfo>>;
fn for_each_object(
&self,
f: &mut dyn FnMut(&ObjectId) -> ControlFlow<()>,
) -> Result<()>;
// Provided methods
fn read_into(
&self,
oid: &ObjectId,
buf: &mut Vec<u8>,
) -> Result<Option<ObjectKind>> { ... }
fn contains(&self, oid: &ObjectId) -> Result<bool> { ... }
fn contains_many(&self, oids: &[ObjectId]) -> Result<Vec<bool>> { ... }
fn open_stream(&self, oid: &ObjectId) -> Result<Option<ObjectStream<'_>>> { ... }
fn lookup_prefix(
&self,
prefix: &str,
limit: usize,
out: &mut Vec<ObjectId>,
) -> Result<()> { ... }
fn refresh(&self) -> Result<bool> { ... }
}Expand description
Read-only object storage: lookup, metadata, streaming, and enumeration.
Implementations must be safe to share across threads (Send + Sync). Missing
objects are reported as Ok(None), not as errors.
Required Methods§
Sourcefn read(&self, oid: &ObjectId) -> Result<Option<Object>>
fn read(&self, oid: &ObjectId) -> Result<Option<Object>>
Load the full object, if present.
§Errors
Returns I/O or corruption errors from the backend; never Error::ObjectNotFound.
Sourcefn for_each_object(
&self,
f: &mut dyn FnMut(&ObjectId) -> ControlFlow<()>,
) -> Result<()>
fn for_each_object( &self, f: &mut dyn FnMut(&ObjectId) -> ControlFlow<()>, ) -> Result<()>
Invoke f for every object id in this store until f returns ControlFlow::Break.
§Errors
Propagates backend enumeration failures.
Provided Methods§
Sourcefn read_into(
&self,
oid: &ObjectId,
buf: &mut Vec<u8>,
) -> Result<Option<ObjectKind>>
fn read_into( &self, oid: &ObjectId, buf: &mut Vec<u8>, ) -> Result<Option<ObjectKind>>
Load object payload into buf, reusing its capacity when possible.
Default implementation delegates to Self::read and copies into buf.
Native backends should inflate or resolve deltas directly into buf.
§Errors
Same as Self::read.
Sourcefn contains(&self, oid: &ObjectId) -> Result<bool>
fn contains(&self, oid: &ObjectId) -> Result<bool>
Whether oid is stored in this backend (without reading the payload).
§Errors
Propagates backend failures other than “not found”.
Sourcefn contains_many(&self, oids: &[ObjectId]) -> Result<Vec<bool>>
fn contains_many(&self, oids: &[ObjectId]) -> Result<Vec<bool>>
For each id in oids, whether it is stored in this backend; the result has
one entry per input id, in input order.
Callers that need to check many objects at once (for example write-tree
confirming that every reusable cached subtree still exists) use this instead
of one Self::contains call per id. The default implementation calls
Self::contains for each id. A database- or network-backed store should
override it to answer the whole batch in a single round trip.
§Errors
Propagates the first backend failure, like Self::contains.
Sourcefn open_stream(&self, oid: &ObjectId) -> Result<Option<ObjectStream<'_>>>
fn open_stream(&self, oid: &ObjectId) -> Result<Option<ObjectStream<'_>>>
Open a stream over the object’s uncompressed payload.
Default implementation buffers via Self::read.
§Errors
Same as Self::read.
Sourcefn lookup_prefix(
&self,
prefix: &str,
limit: usize,
out: &mut Vec<ObjectId>,
) -> Result<()>
fn lookup_prefix( &self, prefix: &str, limit: usize, out: &mut Vec<ObjectId>, ) -> Result<()>
Fill out with object ids whose hex form starts with prefix (case-insensitive).
At most limit ids are appended (0 means no limit). When more than one object
matches and limit is 1, callers treat the result as ambiguous if out would
have held multiple matches.
The default implementation parses prefix once into an ObjectIdPrefix and
compares it against the raw bytes of every id from Self::for_each_object: one
allocation-free pass over the whole store per call. Abbreviating ids and resolving
short ids call this once per id, so a store with many objects and a cheaper way to
find ids by leading bytes (a sorted index, an ordered key-value range from
ObjectIdPrefix::lowest to ObjectIdPrefix::highest) should override it.
§Errors
Returns Error::InvalidObjectId when prefix is not valid hex or is longer
than a full object id for this store’s hash algorithm.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".