Monomorphized directed weighted graph traits

Hi,

I’ve written a set of traits for a graph library, which should allow for monomorphization during compilation, so that multiple implementers can provide an efficient interface to their graphs.

It mainly features a set of types that are associated with the main graph type, which the compiler may use to monomorphize calls to trait methods.

In what ways might I improve the interface and lifetime “situation”?
Right now, essentially everything lives 'a long. Might this cause trouble down the road?

pub type VertexId = usize;

pub trait Vertex<'a, G: DirectedWeightedGraph<'a>>
where
    Self: 'a,
{
    fn id(&'a self) -> VertexId;
    fn adjacent(&'a self) -> G::AdjVertexIterT;
    fn edges(&self) -> G::AdjWeightedEdgeIterT;
}

pub trait WeightedEdge<'a, G: DirectedWeightedGraph<'a>> {
    fn source(&'a self) -> G::VertexT;
    fn target(&'a self) -> G::VertexT;
    fn weight(&self) -> &'a G::Weight;
}

pub trait Vertices<'a, G: DirectedWeightedGraph<'a>> {
    fn iter(&'a self) -> G::VertexIterT;
    fn by_id(&'a self, id: VertexId) -> Option<G::VertexT>;
}

pub trait DirectedWeightedGraph<'a>
where
    Self: 'a + Sized,
{
    type VertexT: Vertex<'a, Self> + 'a;
    type VerticesT: Vertices<'a, Self> + 'a;
    type VertexIterT: Iterator<Item = Self::VertexT> + 'a;
    type AdjVertexIterT: Iterator<Item = Self::VertexT> + 'a;
    type WeightedEdgeT: WeightedEdge<'a, Self>;
    type WeightedEdgeIterT: Iterator<Item = Self::WeightedEdgeT>;
    type AdjWeightedEdgeIterT: Iterator<Item = Self::WeightedEdgeT>;
    type Weight;

    fn vertices(&'a self) -> Self::VerticesT;
    fn edges(&'a self) -> Self::WeightedEdgeIterT;
}

Thanks a lot in advance, for any ideas, suggestions and your time!

Best,
ambiso.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.