1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::{Edge, EdgeStore, Graph, Meta, Metadata, Node, NodeStore};

/// A graph data storage type that allows for more compact serialization.
#[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(),
        }
    }
}