GraphReadWriter

Trait GraphReadWriter 

Source
pub trait GraphReadWriter<NodeWeight, EdgeWeight>: Graph<NodeWeight, EdgeWeight> {
    // Required methods
    fn serialize_graph_to_file(&self, path: &str) -> Result<(), Error>;
    fn deserialize_graph_from_file(path: &str) -> Result<Box<Self>, Error>;
}
Expand description

Trait to serialize and deserialize a given Graph to a file. The file format depends on the graph type being used and can only be assumed compatible with the same graph type.

Required Methods§

Source

fn serialize_graph_to_file(&self, path: &str) -> Result<(), Error>

Serializes a given graph to a file defined by path. The result tells us whether the operation succeeded or not.

Source

fn deserialize_graph_from_file(path: &str) -> Result<Box<Self>, Error>

Deserializes a graph stored in the given file. The result tells us whether the operation succeeded or not.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<NodeWeight, EdgeWeight, EdgeType> GraphReadWriter<NodeWeight, EdgeWeight> for Graph<NodeWeight, EdgeWeight, EdgeType, DefaultIx>
where NodeWeight: Serialize + DeserializeOwned, EdgeWeight: Serialize + DeserializeOwned, EdgeType: EdgeType,

Implementation of GraphReadWriter trait using serde_json. Nodes and Edges need to implement Serializable and Deserializable in order for serde to work.

Source§

fn serialize_graph_to_file(&self, path: &str) -> Result<(), IOError>

Serializes the graph to JSON. This overwrites the file given under path. If serde_json fails, packs the underlying error in an std::io::Error for examination.

Source§

fn deserialize_graph_from_file(path: &str) -> Result<Box<Self>, IOError>

Deserializes a graph stored as JSON, and packs it into a Box. If serde_json fails, packs the underlying error in an std::io::Error for examination.

Implementors§