use crate::{Edge, EdgeStore, Graph, Meta, Metadata, Node, NodeStore};
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(default)
)]
pub struct CompactGraph {
pub metadata: Metadata,
pub nodes: Vec<Node>,
pub edges: Vec<Edge>,
}
impl TryInto<Graph> for CompactGraph {
type Error = crate::graph::Error;
fn try_into(self) -> Result<Graph, Self::Error> {
Graph::new(Some(self.metadata), self.nodes, self.edges)
}
}
impl From<Graph> for CompactGraph {
fn from(value: Graph) -> Self {
Self {
metadata: value.get_meta().to_owned(),
nodes: value.all_nodes().map(|x| x.to_owned()).collect(),
edges: value.all_edges().map(|x| x.to_owned()).collect(),
}
}
}