graph_api_lib/search/
edge.rs1use crate::Direction;
2use crate::element::Element;
3
4#[non_exhaustive]
8pub struct EdgeSearch<'search, Graph>
9where
10 Graph: crate::Graph,
11{
12 _phantom: std::marker::PhantomData<&'search ()>,
14
15 pub label: Option<<Graph::Edge as Element>::Label>,
17
18 pub adjacent_label: Option<<Graph::Vertex as Element>::Label>,
20
21 pub direction: Direction,
23
24 pub limit: Option<usize>,
26}
27
28impl<Graph> Clone for EdgeSearch<'_, Graph>
29where
30 Graph: crate::Graph,
31{
32 fn clone(&self) -> Self {
33 EdgeSearch {
34 _phantom: Default::default(),
35 label: self.label,
36 adjacent_label: self.adjacent_label,
37 direction: self.direction,
38 limit: self.limit,
39 }
40 }
41}
42
43impl<Graph> Default for EdgeSearch<'_, Graph>
44where
45 Graph: crate::Graph,
46{
47 fn default() -> Self {
48 Self {
49 _phantom: Default::default(),
50 label: None,
51 adjacent_label: None,
52 direction: Direction::All,
53 limit: None,
54 }
55 }
56}
57
58impl<Graph> EdgeSearch<'_, Graph>
59where
60 Graph: crate::Graph,
61{
62 pub fn scan() -> Self {
70 Self::default()
71 }
72
73 pub fn label(label: <Graph::Edge as Element>::Label) -> Self {
75 Self {
76 _phantom: Default::default(),
77 label: Some(label),
78 adjacent_label: None,
79 direction: Direction::All,
80 limit: None,
81 }
82 }
83
84 pub fn outgoing(mut self) -> Self {
86 self.direction = Direction::Outgoing;
87 self
88 }
89
90 pub fn incoming(mut self) -> Self {
92 self.direction = Direction::Incoming;
93 self
94 }
95
96 pub fn direction(mut self, direction: Direction) -> Self {
98 self.direction = direction;
99 self
100 }
101
102 pub fn take(mut self, n: usize) -> Self {
106 self.limit = Some(n);
107 self
108 }
109
110 pub fn with_limit(mut self, limit: usize) -> Self {
112 self.limit = Some(limit);
113 self
114 }
115
116 pub fn limit(&self) -> usize {
123 self.limit.unwrap_or(usize::MAX)
124 }
125
126 pub fn adjacent_labelled(mut self, adjacent_label: <Graph::Vertex as Element>::Label) -> Self
128 where
129 Graph: crate::Graph + crate::SupportsEdgeAdjacentLabelIndex,
130 {
131 self.adjacent_label = Some(adjacent_label);
132 self
133 }
134}