use serde::{Deserialize, Serialize};
pub type NodeId = u64;
pub type EdgeId = u64;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum NodeRef {
All,
Ids(Vec<NodeId>),
Var(String),
Param(String),
}
impl NodeRef {
pub fn all() -> Self {
Self::All
}
pub fn id(id: NodeId) -> Self {
Self::Ids(vec![id])
}
pub fn ids(ids: impl IntoIterator<Item = NodeId>) -> Self {
Self::Ids(ids.into_iter().collect())
}
pub fn var(name: impl Into<String>) -> Self {
Self::Var(name.into())
}
pub fn param(name: impl Into<String>) -> Self {
Self::Param(name.into())
}
}
impl From<NodeId> for NodeRef {
fn from(value: NodeId) -> Self {
Self::id(value)
}
}
impl From<Vec<NodeId>> for NodeRef {
fn from(value: Vec<NodeId>) -> Self {
Self::Ids(value)
}
}
impl<const N: usize> From<[NodeId; N]> for NodeRef {
fn from(value: [NodeId; N]) -> Self {
Self::Ids(value.to_vec())
}
}
impl From<&str> for NodeRef {
fn from(value: &str) -> Self {
Self::Var(value.to_string())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum EdgeRef {
All,
Ids(Vec<EdgeId>),
Var(String),
Param(String),
}
impl EdgeRef {
pub fn all() -> Self {
Self::All
}
pub fn id(id: EdgeId) -> Self {
Self::Ids(vec![id])
}
pub fn ids(ids: impl IntoIterator<Item = EdgeId>) -> Self {
Self::Ids(ids.into_iter().collect())
}
pub fn var(name: impl Into<String>) -> Self {
Self::Var(name.into())
}
pub fn param(name: impl Into<String>) -> Self {
Self::Param(name.into())
}
}
impl From<EdgeId> for EdgeRef {
fn from(value: EdgeId) -> Self {
Self::id(value)
}
}
impl From<Vec<EdgeId>> for EdgeRef {
fn from(value: Vec<EdgeId>) -> Self {
Self::Ids(value)
}
}
impl<const N: usize> From<[EdgeId; N]> for EdgeRef {
fn from(value: [EdgeId; N]) -> Self {
Self::Ids(value.to_vec())
}
}