1use std::fmt;
5
6use serde::{Serialize, Serializer};
7
8#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub enum GraphCollection {
11 Node,
13 Reference,
15 Edge,
17}
18
19impl GraphCollection {
20 fn token(self) -> &'static str {
22 match self {
23 Self::Node => "node",
24 Self::Reference => "reference",
25 Self::Edge => "edge",
26 }
27 }
28}
29
30impl fmt::Display for GraphCollection {
33 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
34 formatter.write_str(self.token())
35 }
36}
37
38impl Serialize for GraphCollection {
41 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
42 serializer.serialize_str(self.token())
43 }
44}
45
46#[derive(Clone, Copy, Debug, PartialEq, Eq)]
53pub struct GraphLimits {
54 max_nodes: u32,
55 max_references: u32,
56 max_edges: u32,
57}
58
59impl Default for GraphLimits {
60 fn default() -> Self {
61 Self {
62 max_nodes: u32::MAX,
63 max_references: u32::MAX,
64 max_edges: u32::MAX,
65 }
66 }
67}
68
69impl GraphLimits {
70 pub fn new(max_nodes: u32, max_references: u32, max_edges: u32) -> Self {
72 Self {
73 max_nodes,
74 max_references,
75 max_edges,
76 }
77 }
78
79 pub fn max_nodes(&self) -> u32 {
81 self.max_nodes
82 }
83
84 pub fn max_references(&self) -> u32 {
86 self.max_references
87 }
88
89 pub fn max_edges(&self) -> u32 {
91 self.max_edges
92 }
93
94 pub(crate) fn ceiling(&self, collection: GraphCollection) -> u32 {
96 match collection {
97 GraphCollection::Node => self.max_nodes,
98 GraphCollection::Reference => self.max_references,
99 GraphCollection::Edge => self.max_edges,
100 }
101 }
102}