use super::{PublicDirectory, PublicFile, PublicNode};
use anyhow::Result;
use wnfs_common::{BlockStore, Cid, Link, utils::Arc};
#[derive(Debug, Clone, PartialEq)]
pub struct PublicLink(Link<PublicNode>);
impl PublicLink {
#[inline]
pub fn from_cid(cid: Cid) -> Self {
Self(Link::from_cid(cid))
}
#[inline]
pub fn new(node: PublicNode) -> Self {
Self(Link::from(node))
}
#[inline]
pub fn with_dir(dir: PublicDirectory) -> Self {
Self(Link::from(PublicNode::Dir(Arc::new(dir))))
}
#[inline]
pub fn with_rc_dir(dir: Arc<PublicDirectory>) -> Self {
Self(Link::from(PublicNode::Dir(dir)))
}
#[inline]
pub fn with_file(file: PublicFile) -> Self {
Self(Link::from(PublicNode::File(Arc::new(file))))
}
#[inline]
pub async fn resolve_cid(&self, store: &impl BlockStore) -> Result<Cid> {
self.0.resolve_cid(store).await
}
#[inline]
pub async fn resolve_value(&self, store: &impl BlockStore) -> Result<&PublicNode> {
self.0.resolve_value(store).await
}
#[inline]
pub async fn resolve_value_mut(&mut self, store: &impl BlockStore) -> Result<&mut PublicNode> {
self.0.resolve_value_mut(store).await
}
#[inline]
pub async fn resolve_owned_value(self, store: &impl BlockStore) -> Result<PublicNode> {
self.0.resolve_owned_value(store).await
}
#[inline]
pub async fn deep_eq(&self, other: &Self, store: &impl BlockStore) -> Result<bool> {
self.0.deep_eq(&other.0, store).await
}
}
impl From<PublicNode> for PublicLink {
#[inline]
fn from(value: PublicNode) -> Self {
Self(Link::from(value))
}
}