summaryrefslogtreecommitdiffstats
path: root/src/backend/node.rs
blob: a068405cd3303b72c68a3a0a623222a218da2fb8 (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
30
31
32
33
34
35
36
37
#[derive(Debug, Eq, PartialEq, libipld::DagCbor)]
pub struct Node {
    /// Version
    v: String,

    /// Parent Nodes, identified by cid
    parents: Vec<crate::backend::Id>,

    /// The actual payload of the node, which is stored in another document identified by this cid
    payload: cid::Cid,
}

impl daglib::Node for Node {
    type Id = crate::backend::Id;

    fn parent_ids(&self) -> Vec<Self::Id> {
        self.parents.clone()
    }
}

impl Node {
    pub fn version(&self) -> &str {
        &self.v
    }
    pub fn payload_id(&self) -> &cid::Cid {
        &self.payload
    }

    pub fn new(version: String, parents: Vec<crate::backend::Id>, payload: cid::Cid) -> Self {
        Node {
            v: version,
            parents,
            payload
        }
    }

}