summaryrefslogtreecommitdiffstats
path: root/src/async_dag.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/async_dag.rs')
-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()