1use serde::{Deserialize, Serialize};
2
3pub type NodeId = u64;
5
6pub type EdgeId = u64;
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum NodeRef {
12 All,
14 Ids(Vec<NodeId>),
16 Var(String),
18 Param(String),
20}
21
22impl NodeRef {
23 pub fn all() -> Self {
25 Self::All
26 }
27
28 pub fn id(id: NodeId) -> Self {
30 Self::Ids(vec![id])
31 }
32
33 pub fn ids(ids: impl IntoIterator<Item = NodeId>) -> Self {
35 Self::Ids(ids.into_iter().collect())
36 }
37
38 pub fn var(name: impl Into<String>) -> Self {
40 Self::Var(name.into())
41 }
42
43 pub fn param(name: impl Into<String>) -> Self {
45 Self::Param(name.into())
46 }
47}
48
49impl From<NodeId> for NodeRef {
50 fn from(value: NodeId) -> Self {
51 Self::id(value)
52 }
53}
54
55impl From<Vec<NodeId>> for NodeRef {
56 fn from(value: Vec<NodeId>) -> Self {
57 Self::Ids(value)
58 }
59}
60
61impl<const N: usize> From<[NodeId; N]> for NodeRef {
62 fn from(value: [NodeId; N]) -> Self {
63 Self::Ids(value.to_vec())
64 }
65}
66
67impl From<&str> for NodeRef {
68 fn from(value: &str) -> Self {
69 Self::Var(value.to_string())
70 }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
75#[serde(rename_all = "snake_case")]
76pub enum EdgeRef {
77 All,
79 Ids(Vec<EdgeId>),
81 Var(String),
83 Param(String),
85}
86
87impl EdgeRef {
88 pub fn all() -> Self {
90 Self::All
91 }
92
93 pub fn id(id: EdgeId) -> Self {
95 Self::Ids(vec![id])
96 }
97
98 pub fn ids(ids: impl IntoIterator<Item = EdgeId>) -> Self {
100 Self::Ids(ids.into_iter().collect())
101 }
102
103 pub fn var(name: impl Into<String>) -> Self {
105 Self::Var(name.into())
106 }
107
108 pub fn param(name: impl Into<String>) -> Self {
110 Self::Param(name.into())
111 }
112}
113
114impl From<EdgeId> for EdgeRef {
115 fn from(value: EdgeId) -> Self {
116 Self::id(value)
117 }
118}
119
120impl From<Vec<EdgeId>> for EdgeRef {
121 fn from(value: Vec<EdgeId>) -> Self {
122 Self::Ids(value)
123 }
124}
125
126impl<const N: usize> From<[EdgeId; N]> for EdgeRef {
127 fn from(value: [EdgeId; N]) -> Self {
128 Self::Ids(value.to_vec())
129 }
130}