radicle: add Op::load method
Adds an `Op::load` helper method for loading an `Entry`, given its `Oid` and the `store` it is stored in. This can be useful for downstream consumers to inspect operations on COBs given a single `Oid`, without having to load the entire object and/or graph. It can also be useful when looking at implementing COB stream primitives.
This commit is contained in:
parent
dbfcf424d6
commit
9b59c0e2c6
|
|
@ -35,17 +35,15 @@ pub struct ManifestError {
|
|||
/// Error loading an `Op` from storage.
|
||||
#[derive(Error, Debug)]
|
||||
pub enum LoadError {
|
||||
#[error("failed to load Op at '{object}': {err}")]
|
||||
#[error("failed to load Op at '{object}': {source}")]
|
||||
Load {
|
||||
object: git::Oid,
|
||||
#[source]
|
||||
err: Box<dyn std::error::Error + Send + Sync + 'static>,
|
||||
source: Box<dyn std::error::Error + Send + Sync + 'static>,
|
||||
},
|
||||
#[error("failed to decode Op at '{object}': {err}")]
|
||||
#[error("failed to decode Op at '{object}': {source}")]
|
||||
Encoding {
|
||||
object: git::Oid,
|
||||
#[source]
|
||||
err: OpEncodingError,
|
||||
source: OpEncodingError,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -146,9 +144,12 @@ impl<A> Op<A> {
|
|||
{
|
||||
let entry = store.load(id).map_err(|err| LoadError::Load {
|
||||
object: id,
|
||||
err: Box::new(err),
|
||||
source: Box::new(err),
|
||||
})?;
|
||||
Op::try_from(&entry).map_err(|err| LoadError::Encoding { object: id, err })
|
||||
Op::try_from(&entry).map_err(|err| LoadError::Encoding {
|
||||
object: id,
|
||||
source: err,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue