indradb/models/
properties.rs

1use crate::{Edge, Identifier, Json, Vertex};
2
3use uuid::Uuid;
4
5/// Represents a vertex property.
6#[derive(Clone, Debug, PartialEq)]
7pub struct VertexProperty {
8    /// The id of the vertex.
9    pub id: Uuid,
10
11    /// The property value.
12    pub value: Json,
13}
14
15impl VertexProperty {
16    /// Creates a new vertex property.
17    ///
18    /// # Arguments
19    /// * `id`: The id of the vertex.
20    /// * `value`: The property value.
21    pub fn new(id: Uuid, value: Json) -> Self {
22        Self { id, value }
23    }
24}
25
26/// A property.
27#[derive(Clone, Debug, PartialEq)]
28pub struct NamedProperty {
29    /// The property name.
30    pub name: Identifier,
31
32    /// The property value.
33    pub value: Json,
34}
35
36impl NamedProperty {
37    /// Creates a new vertex property.
38    ///
39    /// # Arguments
40    /// * `name`: The name of the property.
41    /// * `value`: The property value.
42    pub fn new(name: Identifier, value: Json) -> Self {
43        Self { name, value }
44    }
45}
46
47/// A vertex with properties.
48#[derive(Clone, Debug, PartialEq)]
49pub struct VertexProperties {
50    /// The vertex.
51    pub vertex: Vertex,
52    /// All of the vertex's properties.
53    pub props: Vec<NamedProperty>,
54}
55
56impl VertexProperties {
57    /// Creates new properties for a given vertex.
58    ///
59    /// # Arguments
60    /// * `vertex`: The vertex information
61    /// * `props`: The properties
62    pub fn new(vertex: Vertex, props: Vec<NamedProperty>) -> Self {
63        VertexProperties { vertex, props }
64    }
65}
66
67/// An edge with properties.
68#[derive(Clone, Debug, PartialEq)]
69pub struct EdgeProperties {
70    /// The edge.
71    pub edge: Edge,
72    /// All of the edge's properties.
73    pub props: Vec<NamedProperty>,
74}
75
76impl EdgeProperties {
77    /// Creates a new edge properties for a given edge.
78    ///
79    /// # Arguments
80    /// * `edge`: The edge information
81    /// * `props`: The properties
82    pub fn new(edge: Edge, props: Vec<NamedProperty>) -> Self {
83        EdgeProperties { edge, props }
84    }
85}
86
87/// Represents an edge property.
88#[derive(Clone, Debug, PartialEq)]
89pub struct EdgeProperty {
90    /// The edge.
91    pub edge: Edge,
92
93    /// The property value.
94    pub value: Json,
95}
96
97impl EdgeProperty {
98    /// Creates a new edge property.
99    ///
100    /// # Arguments
101    /// * `edge`: The edge.
102    /// * `value`: The property value.
103    pub fn new(edge: Edge, value: Json) -> Self {
104        Self { edge, value }
105    }
106}