kotoba_graph/graph/
edge.rs1use std::collections::HashMap;
4use kotoba_core::types::*;
5
6#[derive(Debug, Clone)]
8pub struct EdgeBuilder {
9 id: Option<EdgeId>,
10 src: Option<VertexId>,
11 dst: Option<VertexId>,
12 label: Option<Label>,
13 props: Properties,
14}
15
16impl Default for EdgeBuilder {
17 fn default() -> Self {
18 Self::new()
19 }
20}
21
22impl EdgeBuilder {
23 pub fn new() -> Self {
24 Self {
25 id: None,
26 src: None,
27 dst: None,
28 label: None,
29 props: HashMap::new(),
30 }
31 }
32
33 pub fn id(mut self, id: EdgeId) -> Self {
34 self.id = Some(id);
35 self
36 }
37
38 pub fn src(mut self, src: VertexId) -> Self {
39 self.src = Some(src);
40 self
41 }
42
43 pub fn dst(mut self, dst: VertexId) -> Self {
44 self.dst = Some(dst);
45 self
46 }
47
48 pub fn label(mut self, label: Label) -> Self {
49 self.label = Some(label);
50 self
51 }
52
53 pub fn prop(mut self, key: PropertyKey, value: Value) -> Self {
54 self.props.insert(key, value);
55 self
56 }
57
58 pub fn props(mut self, props: Properties) -> Self {
59 self.props = props;
60 self
61 }
62
63 pub fn build(self) -> crate::graph::EdgeData {
64 crate::graph::EdgeData {
65 id: self.id.unwrap_or_else(uuid::Uuid::new_v4),
66 src: self.src.expect("src must be set"),
67 dst: self.dst.expect("dst must be set"),
68 label: self.label.expect("label must be set"),
69 props: self.props,
70 }
71 }
72}