gremlin_client/structure/
edge.rs

1use crate::structure::{Property, Vertex, GID};
2use std::collections::hash_map::{IntoIter, Iter};
3use std::collections::HashMap;
4use std::hash::Hasher;
5
6#[derive(Debug, Clone)]
7pub struct Edge {
8    id: GID,
9    label: String,
10    in_v: Vertex,
11    out_v: Vertex,
12    properties: HashMap<String, Property>,
13}
14
15impl Edge {
16    pub(crate) fn new<T>(
17        id: GID,
18        label: T,
19        in_v_id: GID,
20        in_v_label: T,
21        out_v_id: GID,
22        out_v_label: T,
23        properties: HashMap<String, Property>,
24    ) -> Edge
25    where
26        T: Into<String>,
27    {
28        Edge {
29            id,
30            label: label.into(),
31            in_v: Vertex::new(in_v_id, in_v_label, HashMap::new()),
32            out_v: Vertex::new(out_v_id, out_v_label, HashMap::new()),
33            properties,
34        }
35    }
36
37    pub fn id(&self) -> &GID {
38        &self.id
39    }
40
41    pub fn label(&self) -> &String {
42        &self.label
43    }
44
45    pub fn in_v(&self) -> &Vertex {
46        &self.in_v
47    }
48    pub fn out_v(&self) -> &Vertex {
49        &self.out_v
50    }
51
52    pub fn iter(&self) -> Iter<String, Property> {
53        self.properties.iter()
54    }
55
56    pub fn property(&self, key: &str) -> Option<&Property> {
57        self.properties.get(key)
58    }
59}
60
61impl IntoIterator for Edge {
62    type Item = (String, Property);
63    type IntoIter = IntoIter<String, Property>;
64    fn into_iter(self) -> Self::IntoIter {
65        self.properties.into_iter()
66    }
67}
68
69impl std::cmp::Eq for Edge {}
70
71impl PartialEq for Edge {
72    fn eq(&self, other: &Edge) -> bool {
73        &self.id == other.id()
74    }
75}
76
77impl std::hash::Hash for Edge {
78    fn hash<H: Hasher>(&self, state: &mut H) {
79        self.id.hash(state);
80    }
81}