//! This library defines a binary format to store graph data such that //! a client which understands the format can easily print the graph, //! centered at any specific node, with any scope. The library also //! provides functions to print graphs in this format. //! //! This way, one does not need a server to print and interact with //! graphs. //! //! # Graph representation //! //! The library uses the [`Graph`][graph::Graph] trait from the crate //! [graph]. Only the functions exposed from the trait are used by //! this library. So the users can also implement the trait and then //! print the graph data represented by other graph crates. extern crate graph; use graph::Graph; use std::{error::Error, path::Path}; pub mod strong_component; pub mod decycle; pub trait Action: Sized { type Karmani: Graph; type Error: Error; fn perform(&self, obj: &mut Self::Karmani) -> Result<(), Self::Error>; fn serialize(&self) -> Vec; fn deserialize(bytes: impl AsRef<[u8]>) -> Result, Self::Error>; } #[allow(unused)] pub fn serialize( actions: Vec, filename: &Path, final_p: bool, ) -> Result<(), ::Error> { Ok(()) } pub fn deserialize( bytes: impl AsRef<[u8]>, ) -> Result<(Vec, ::Karmani), ::Error> { let mut bytes = bytes.as_ref(); let mut result_actions = Vec::new(); let mut result_karmanayah = Default::default(); while let Some((action, offset)) = A::deserialize(bytes)? { action.perform(&mut result_karmanayah)?; result_actions.push(action); bytes = &bytes[offset..]; } let result = (result_actions, result_karmanayah); Ok(result) } // TODO: Figure out the parts to display graphs.