summaryrefslogtreecommitdiffstats
path: root/src/profile.rs
blob: 26ac6bb7877b8903b822a0913fc8151d8f587aa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::collections::HashMap;

use anyhow::Result;

use crate::backend::Id;
use crate::backend::Node;
use crate::backend::IpfsEmbedBackend;

pub struct Profile {
    dag: daglib::AsyncDag<Id, Node, IpfsEmbedBackend>,

    cache: HashMap<cid::Cid, LoadedNode>,
}

impl Profile {
    pub async fn load(head: Id) -> Result<Self> {
        let backend = IpfsEmbedBackend::new_in_memory(1000).await?;
        let dag = daglib::AsyncDag::load(backend, head).await?;
        let cache = HashMap::new();
        Ok(Profile { dag, cache })
    }

    pub async fn create(node: Node) -> Result<Self> {
        let backend = IpfsEmbedBackend::new_in_memory(1000).await?;
        let dag = daglib::AsyncDag::new(backend, node).await?;
        let cache = HashMap::new();
        Ok(Profile { dag, cache })
    }
}