use crate::{Edge, EdgeStore, Graph, Meta, Metadata, Node, NodeStore};
use anyhow::{Error, Result};
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CompactGraph {
pub metadata: Metadata,
pub nodes: Vec<Node>,
pub edges: Vec<Edge>,
}
impl TryInto<Graph> for CompactGraph {
type Error = Error;
fn try_into(self) -> Result<Graph> {
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()
.into_iter()
.map(|x| x.to_owned())
.collect(),
edges: value
.all_edges()
.into_iter()
.map(|x| x.to_owned())
.collect(),
}
}
}