37 lines
810 B
Rust
Raw Normal View History

2025-04-02 18:23:03 -04:00
use std::sync::Arc;
2025-03-29 16:06:11 -04:00
use serde::{Serialize, Deserialize};
2025-04-02 18:23:03 -04:00
#[derive(Serialize, Deserialize, Debug)]
2025-03-29 16:06:11 -04:00
pub struct Reference {
2025-04-02 18:23:03 -04:00
pub object_id: String,
pub content_address: String,
pub path: String,
2025-03-29 16:06:11 -04:00
#[serde(skip_serializing_if = "Vec::is_empty")]
2025-04-02 18:23:03 -04:00
pub dependents: Vec<Arc<Reference>>,
2025-03-29 16:06:11 -04:00
}
impl Reference {
2025-03-30 15:02:46 -04:00
pub fn new(object_id: String, content_address: String, path: String) -> Self {
2025-03-29 16:06:11 -04:00
Self {
object_id,
2025-03-30 15:02:46 -04:00
content_address,
2025-03-29 16:06:11 -04:00
path,
dependents: Vec::new(),
}
}
2025-04-02 18:23:03 -04:00
pub fn add_dep(mut self, dep: Arc<Reference>) -> Self {
2025-03-29 16:06:11 -04:00
self.dependents.push(dep);
self
}
2025-04-02 18:23:03 -04:00
pub fn to_arc(self) -> Arc<Self> {
Arc::new(self)
}
pub fn is_leaf(&self) -> bool {
return self.dependents.is_empty();
2025-03-29 16:06:11 -04:00
}
}