use crate::graph::{
Graph, GraphMut,
node::{Node, NodeMut},
};
pub trait Edge<'graph> {
type Graph: Graph;
fn new(id: <Self::Graph as Graph>::EdgeId, graph: &'graph Self::Graph) -> Self;
fn id(&self) -> <Self::Graph as Graph>::EdgeId;
fn graph(&self) -> &'graph Self::Graph;
#[allow(clippy::wrong_self_convention)]
fn from_id(&self) -> <Self::Graph as Graph>::NodeId;
fn to_id(&self) -> <Self::Graph as Graph>::NodeId;
fn from(&self) -> <Self::Graph as Graph>::Node<'graph> {
let id = self.from_id();
<Self::Graph as Graph>::Node::new(id, self.graph())
}
fn to(&self) -> <Self::Graph as Graph>::Node<'graph> {
let id = self.to_id();
<Self::Graph as Graph>::Node::new(id, self.graph())
}
fn is_loop(&self) -> bool {
self.from_id() == self.to_id()
}
}
pub trait EdgeMut<'graph> {
type Graph: GraphMut;
fn new(id: <Self::Graph as Graph>::EdgeId, graph: &'graph mut Self::Graph) -> Self;
fn id(&self) -> <Self::Graph as Graph>::EdgeId;
fn graph(&mut self) -> &mut Self::Graph;
#[allow(clippy::wrong_self_convention)]
fn from_id(&self) -> <Self::Graph as Graph>::NodeId;
fn from(&mut self) -> <Self::Graph as GraphMut>::NodeMut<'_> {
let id = self.from_id();
<Self::Graph as GraphMut>::NodeMut::new(id, self.graph())
}
fn to_id(&self) -> <Self::Graph as Graph>::NodeId;
fn to(&mut self) -> <Self::Graph as GraphMut>::NodeMut<'_> {
let id = self.to_id();
<Self::Graph as GraphMut>::NodeMut::new(id, self.graph())
}
fn set_from(&mut self, node: <Self::Graph as Graph>::NodeId);
fn as_ref(&mut self) -> <Self::Graph as Graph>::Edge<'_> {
<Self::Graph as Graph>::Edge::new(self.id(), &*self.graph())
}
}