graphfind_rs/graph/file_io.rs
1use std::io;
2
3use crate::graph::Graph;
4
5/// Trait to serialize and deserialize a given Graph to a file.
6/// The file format depends on the graph type being used and can only
7/// be assumed compatible with the same graph type.
8pub trait GraphReadWriter<NodeWeight, EdgeWeight>: Graph<NodeWeight, EdgeWeight> {
9 /// Serializes a given graph to a file defined by path.
10 /// The result tells us whether the operation succeeded or not.
11 fn serialize_graph_to_file(&self, path: &str) -> Result<(), io::Error>;
12
13 /// Deserializes a graph stored in the given file.
14 /// The result tells us whether the operation succeeded or not.
15 fn deserialize_graph_from_file(path: &str) -> Result<Box<Self>, io::Error>;
16}