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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
//! 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<u8>;
fn deserialize(bytes: impl AsRef<[u8]>) -> Result<Option<(Self, usize)>, Self::Error>;
}
#[allow(unused)]
pub fn serialize<A: Action>(
actions: Vec<A>,
filename: &Path,
final_p: bool,
) -> Result<(), <A as Action>::Error> {
Ok(())
}
pub fn deserialize<A: Action>(
bytes: impl AsRef<[u8]>,
) -> Result<(Vec<A>, <A as Action>::Karmani), <A as Action>::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.
|