summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-04-05 11:53:29 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-04-05 11:53:29 +0200
commit731549ac1d08df6c956be672353e11c4aac1716f (patch)
tree3a0027db170f54947ee96030dfa6d50bdb2f3bf0
parent78ab04989b0e343f815822f27d24254097465db0 (diff)
Add AsyncDag::load()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/async_dag.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/async_dag.rs b/src/async_dag.rs
index 0da6e2c..88a839e 100644
--- a/src/async_dag.rs
+++ b/src/async_dag.rs
@@ -47,6 +47,24 @@ impl<Id, N, Backend> AsyncDag<Id, N, Backend>
})
}
+ /// Load a AsyncDag object using `head` as HEAD node.
+ ///
+ /// # Warning
+ ///
+ /// This fails if backend.get(head) fails.
+ pub async fn load(backend: Backend, head: Id) -> Result<Self> {
+ backend.get(head)
+ .await?
+ .map(|(id, _)| {
+ AsyncDag {
+ head: id,
+ backend: backend,
+ _node: std::marker::PhantomData,
+ }
+ })
+ .ok_or_else(|| anyhow!("Node not found"))
+ }
+
/// Check whether an `id` is in the DAG.
pub async fn has_id(&self, id: &Id) -> Result<bool> {
self.stream()