ipld_block_builder/
path.rs

1use libipld::cid::Cid;
2pub use libipld::path::Path as IpldPath;
3
4/// Path in a dag.
5#[derive(Clone, Debug, PartialEq, Hash)]
6pub struct DagPath<'a>(&'a Cid, IpldPath);
7
8impl<'a> DagPath<'a> {
9    /// Create a new dag path.
10    pub fn new<T: Into<IpldPath>>(cid: &'a Cid, path: T) -> Self {
11        Self(cid, path.into())
12    }
13
14    /// Returns the root of the path.
15    pub fn root(&self) -> &Cid {
16        self.0
17    }
18
19    /// Returns the ipld path.
20    pub fn path(&self) -> &IpldPath {
21        &self.1
22    }
23}
24
25impl<'a> From<&'a Cid> for DagPath<'a> {
26    fn from(cid: &'a Cid) -> Self {
27        Self(cid, Default::default())
28    }
29}