1use crate::{Edge, EdgeStore, Graph, Meta, Metadata, Node, NodeStore};
12
13#[derive(Clone, Debug, Default, PartialEq)]
15#[cfg_attr(
16 feature = "serde",
17 derive(serde::Serialize, serde::Deserialize),
18 serde(default)
19)]
20pub struct CompactGraph {
21 pub metadata: Metadata,
22 pub nodes: Vec<Node>,
23 pub edges: Vec<Edge>,
24}
25impl TryInto<Graph> for CompactGraph {
26 type Error = crate::graph::Error;
27 fn try_into(self) -> Result<Graph, Self::Error> {
28 Graph::new(Some(self.metadata), self.nodes, self.edges)
29 }
30}
31impl From<Graph> for CompactGraph {
32 fn from(value: Graph) -> Self {
33 Self {
34 metadata: value.get_meta().to_owned(),
35 nodes: value.all_nodes().map(|x| x.to_owned()).collect(),
36 edges: value.all_edges().map(|x| x.to_owned()).collect(),
37 }
38 }
39}