ratio-graph 0.23.3

Ratio's graph manipulation library.
Documentation
//! # Serialization module
//!
//! ## License
//!
//! This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
//! If a copy of the MPL was not distributed with this file,
//! You can obtain one at <https://mozilla.org/MPL/2.0/>.
//!
//! **Code examples both in the docstrings and rendered documentation are free to use.**

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(),
        }
    }
}