A Claude-written graph database in Rust. Use at your own risk.
at main 44 lines 1.0 kB view raw
1use serde::{Deserialize, Serialize}; 2use crate::{NodeId, LabelId}; 3use crate::core::property::PropertyMap; 4 5#[derive(Debug, Clone, Serialize, Deserialize)] 6pub struct Node { 7 pub id: NodeId, 8 pub labels: Vec<LabelId>, 9 pub properties: PropertyMap, 10} 11 12impl Node { 13 pub fn new(id: NodeId) -> Self { 14 Self { 15 id, 16 labels: Vec::new(), 17 properties: PropertyMap::new(), 18 } 19 } 20 21 pub fn with_labels(mut self, labels: Vec<LabelId>) -> Self { 22 self.labels = labels; 23 self 24 } 25 26 pub fn with_properties(mut self, properties: PropertyMap) -> Self { 27 self.properties = properties; 28 self 29 } 30 31 pub fn add_label(&mut self, label: LabelId) { 32 if !self.labels.contains(&label) { 33 self.labels.push(label); 34 } 35 } 36 37 pub fn remove_label(&mut self, label: LabelId) { 38 self.labels.retain(|&l| l != label); 39 } 40 41 pub fn has_label(&self, label: LabelId) -> bool { 42 self.labels.contains(&label) 43 } 44}