indradb/models/edges.rs
1use super::Identifier;
2
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6/// An edge.
7///
8/// Edges are how you would represent a verb or a relationship in the
9/// datastore. An example might be "liked" or "reviewed". Edges are typed and
10/// directed.
11#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize)]
12pub struct Edge {
13 /// The id of the outbound vertex.
14 pub outbound_id: Uuid,
15
16 /// The type of the edge.
17 pub t: Identifier,
18
19 /// The id of the inbound vertex.
20 pub inbound_id: Uuid,
21}
22
23impl Edge {
24 /// Creates a new edge key.
25 ///
26 /// # Arguments
27 ///
28 /// * `outbound_id`: The id of the outbound vertex.
29 /// * `t`: The type of the edge.
30 /// * `inbound_id`: The id of the inbound vertex.
31 pub fn new(outbound_id: Uuid, t: Identifier, inbound_id: Uuid) -> Edge {
32 Edge {
33 outbound_id,
34 t,
35 inbound_id,
36 }
37 }
38
39 /// Produces a new edge key that is a reversed version of this one; i.e.
40 /// it has the same type, but the outbound and inbound IDs are flipped.
41 pub fn reversed(&self) -> Edge {
42 Edge::new(self.inbound_id, self.t, self.outbound_id)
43 }
44}