pchampin / sophia_rs

Sophia: a Rust toolkit for RDF and Linked Data
Other
214 stars 23 forks source link

Provide a common abstraction of TripleSource and QuadSource #52

Closed MattesWhite closed 5 months ago

MattesWhite commented 4 years ago

This PR originates from the discussion in #49 starting with this comment.

Summary

Problems

  1. Implementing traits with associated traits does not consider trait bounds. Meaning is there is an adapter Normalizer<S> one can only implement either Iterator<Item = Triple> for Normalizer<S: TripleSource> or Iterator<Item = Quad> for Normalizer<S: QuadSource>. Both together would result in conflicting implementation.
  2. Splitted implementations violate privacy bounds. Declaring a struct in crate::triple::stream and implementing QuadSource in crate::quad::stream requires the fields to be pub(crate) at least.

Solutions

For 1.: Maybe some overall abstraction for statements?

For 2.: Merge the stream submodules into a top-level module stream equal to triple and quad.

pchampin commented 4 years ago

Merge the stream submodules into a top-level module stream equal to triple and quad.

I started trying this out, factorizing some of the code into a StatementSource trait, then defining specializations of it as TripleSource and QuadSource. But I ran into the following problem:

One can not easily use the specialized traits in a trait bound. Instead of writing

        pub fn consume_triple_source<TS: TripleSource>(mut ts: TS) 
        { /*...*/ }

one needs to write

        pub fn consume_triple_source<TS: TripleSource>(mut ts: TS) 
        where <TS::Mode as StreamingMode>::Item: UnsafeTriple
        { /*...*/ }

which is unintuitive and cumbersome. This does not go in the direction of making the API easier...

I put a summarized version of this problem in the playground.

pchampin commented 8 months ago

I need to see if GATs can be used to solve this issue, otherwise I'll close it as wontfix.