Skip to main content

ipld_car/dag_pb/
link.rs

1use derive_more::From;
2use derive_new::new;
3
4#[derive(From, Debug)]
5pub enum Link {
6	Named(#[from] NamedLink),
7	Block(#[from] BlockLink),
8}
9
10impl Link {
11	pub fn name(&self) -> Option<&str> {
12		match self {
13			Self::Named(named) => Some(named.name.as_str()),
14			Self::Block(..) => None,
15		}
16	}
17
18	pub fn cumulative_dag_size(&self) -> u64 {
19		match self {
20			Self::Named(..) => 0u64,
21			Self::Block(bl) => bl.cumulative_dag_size,
22		}
23	}
24}
25
26#[derive(new, Debug)]
27pub struct NamedLink {
28	#[new(into)]
29	pub name: String,
30}
31
32#[derive(new, Debug)]
33pub struct BlockLink {
34	pub cumulative_dag_size: u64,
35}