kotoba_core/graph/
vertex.rs

1//! 頂点関連構造体
2
3use std::collections::HashMap;
4use crate::types::*;
5
6/// 頂点ビルダー
7#[derive(Debug, Clone)]
8pub struct VertexBuilder {
9    id: Option<VertexId>,
10    labels: Vec<Label>,
11    props: Properties,
12}
13
14impl VertexBuilder {
15    pub fn new() -> Self {
16        Self {
17            id: None,
18            labels: Vec::new(),
19            props: HashMap::new(),
20        }
21    }
22
23    pub fn id(mut self, id: VertexId) -> Self {
24        self.id = Some(id);
25        self
26    }
27
28    pub fn label(mut self, label: Label) -> Self {
29        self.labels.push(label);
30        self
31    }
32
33    pub fn labels(mut self, labels: Vec<Label>) -> Self {
34        self.labels = labels;
35        self
36    }
37
38    pub fn prop(mut self, key: PropertyKey, value: Value) -> Self {
39        self.props.insert(key, value);
40        self
41    }
42
43    pub fn props(mut self, props: Properties) -> Self {
44        self.props = props;
45        self
46    }
47
48    pub fn build(self) -> crate::graph::VertexData {
49        crate::graph::VertexData {
50            id: self.id.unwrap_or_else(|| uuid::Uuid::new_v4()),
51            labels: self.labels,
52            props: self.props,
53        }
54    }
55}