use petgraph::graph::NodeIndex;
use super::{Graph, Weight};
pub trait ByteNode<T>: Copy + From<NodeIndex> + Into<NodeIndex>
where
for<'a> T: From<&'a Vec<u8>>,
for<'a> &'a T: Into<Vec<u8>>,
{
fn read(self, graph: &Graph) -> T {
match &graph[self.into()] {
Weight::Bytes(bytes) => bytes.into(),
_ => panic!("Incorrect weight type"),
}
}
fn write(self, graph: &mut Graph, weight: &T) {
graph[self.into()] = Weight::Bytes(weight.into());
}
}