summaryrefslogtreecommitdiffstats
path: root/libimagref
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-06-28 23:01:42 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-07-04 19:29:02 +0200
commita240b997734671c57bfa59429c2ea8376b40c976 (patch)
tree25ae3a8a6294e4ff72b1f244208ab5b67268e114 /libimagref
parent38557e9a9b3288fd57d49b41c9512f9ead7a4d1a (diff)
Impl Ref::get_by_hash()
Diffstat (limited to 'libimagref')
-rw-r--r--libimagref/src/reference.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/libimagref/src/reference.rs b/libimagref/src/reference.rs
index d10953e5..e1ed79b9 100644
--- a/libimagref/src/reference.rs
+++ b/libimagref/src/reference.rs
@@ -38,6 +38,17 @@ impl<'a> Ref<'a> {
}
}
+ /// Get a Ref object from the store by hash.
+ ///
+ /// Returns None if the hash cannot be found.
+ pub fn get_by_hash(store: &'a Store, hash: String) -> Result<Option<Ref<'a>>> {
+ store
+ .get(ModuleEntryPath::new(hash).into_storeid())
+ .map(|opt_fle| opt_fle.map(|fle| Ref(fle)))
+ .map_err(Box::new)
+ .map_err(|e| REK::StoreReadError.into_error_with_cause(e))
+ }
+
/// Delete this ref
///
/// If the returned Result contains an error, the ref might not be deleted.