Closed MattesWhite closed 4 years ago
In general, I think that the API should not impose the use of trait objects. Assuming we have a Term
trait, having functions accept &T where T: Term
is the best option: people who want compile-time optimization can pass references to concrete types; people who want to avoid monomorphization can restrict themselves to passing exclusively dyn
references. Everyone can have it their way.
I made one exception to that rule: Graph
/Dataset
methods return a boxed iterator (hence a trait object), because 1/ it allows for a default implementation, and 2/ the alternative was horribly cumbersome (declaring a bunch of associated types...).
Can we close this, then?
During #55 the question arose how should read-only
Term
references be handled.Note: This only affects situation where a
Term
is passed in to check and compare the contents of it. Not when theTerm
(reference) is passed in to be copy/clone in some way.Currently, there are two approaches in
sophia
:Term
, e.g.Graph::triples_with_spo<'s, T, U, V>(&'s self, s: &'s Term<T>, p: &'s Term<U>, o: &'s Term<V>) -> GTripleSource<'s, Self>
. This version allows to directly pass references without the need to create an intermediate representation. However, this can increase compile times and code size significantly.RefTerm
. This prevents monomorphization. However, it requires to build an intermediate, 76 Byte bigRefTerm
.An alternative approach would be having a
TermTrait
, so we could pass&dyn TermTrait
in such situations. This would prevent monomorphization and does not require an intermediateRefTerm
. However, a definition of such a trait is still to be figured out.