pub trait Find {
// Required methods
fn contains(&self, id: &oid) -> bool;
fn try_find_cached<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
pack_cache: &mut dyn DecodeEntry
) -> Result<Option<(Data<'a>, Option<Location>)>, Error>;
fn location_by_oid(&self, id: &oid, buf: &mut Vec<u8>) -> Option<Location>;
fn pack_offsets_and_oid(
&self,
pack_id: u32
) -> Option<Vec<(Offset, ObjectId)>>;
fn entry_by_location(&self, location: &Location) -> Option<Entry>;
// Provided method
fn try_find<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>
) -> Result<Option<(Data<'a>, Option<Location>)>, Error> { ... }
}
Expand description
Describe how object can be located in an object store with built-in facilities to supports packs specifically.
Notes
Find effectively needs generic associated types to allow a trait for the returned object type. Until then, we will have to make due with explicit types and give them the potentially added features we want.
Furthermore, despite this trait being in gix-pack
, it leaks knowledge about objects potentially not being packed.
This is a necessary trade-off to allow this trait to live in gix-pack
where it is used in functions to create a pack.
Required Methods§
sourcefn try_find_cached<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
pack_cache: &mut dyn DecodeEntry
) -> Result<Option<(Data<'a>, Option<Location>)>, Error>
fn try_find_cached<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, pack_cache: &mut dyn DecodeEntry ) -> Result<Option<(Data<'a>, Option<Location>)>, Error>
Like Find::try_find()
, but with support for controlling the pack cache.
A pack_cache
can be used to speed up subsequent lookups, set it to crate::cache::Never
if the
workload isn’t suitable for caching.
Returns Some((<object data>, <pack location if packed>))
if it was present in the database,
or the error that occurred during lookup or object retrieval.
sourcefn location_by_oid(&self, id: &oid, buf: &mut Vec<u8>) -> Option<Location>
fn location_by_oid(&self, id: &oid, buf: &mut Vec<u8>) -> Option<Location>
Find the packs location where an object with id
can be found in the database, or None
if there is no pack
holding the object.
Note that this is always None if the object isn’t packed even though it exists as loose object.
sourcefn pack_offsets_and_oid(&self, pack_id: u32) -> Option<Vec<(Offset, ObjectId)>>
fn pack_offsets_and_oid(&self, pack_id: u32) -> Option<Vec<(Offset, ObjectId)>>
Obtain a vector of all offsets, in index order, along with their object id.
sourcefn entry_by_location(&self, location: &Location) -> Option<Entry>
fn entry_by_location(&self, location: &Location) -> Option<Entry>
Return the find::Entry
for location
if it is backed by a pack.
Note that this is only in the interest of avoiding duplicate work during pack generation.
Pack locations can be obtained from Find::try_find()
.
Notes
Custom implementations might be interested in providing their own meta-data with object
,
which currently isn’t possible as the Locate
trait requires GATs to work like that.
Provided Methods§
sourcefn try_find<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>
) -> Result<Option<(Data<'a>, Option<Location>)>, Error>
fn try_find<'a>( &self, id: &oid, buffer: &'a mut Vec<u8> ) -> Result<Option<(Data<'a>, Option<Location>)>, Error>
Find an object matching id
in the database while placing its raw, decoded data into buffer
.
A pack_cache
can be used to speed up subsequent lookups, set it to crate::cache::Never
if the
workload isn’t suitable for caching.
Returns Some((<object data>, <pack location if packed>))
if it was present in the database,
or the error that occurred during lookup or object retrieval.