Closed frankmcsherry closed 5 years ago
Looking at the code a bit more, there is the potential for further clean-up. Specifically, the ExtendAnti
implementations are identical for both &'a Val
and Val: Clone
, as neither proposes a value and instead only seems to require that the type implement Deref<Target=Val>
. It might be over-engineering things a bit to fit that it, and the copy-paste second implementation isn't horrible yet. But, fyi.
Playing around with this a bit, I'm not sure I would recommend it. This doesn't play especially well with the intent of providing treefrog implementations for Variable
, as .. the traits one needs to generalize for that implementation conflict a bit with the generality here. I'm sure it is possible to do both (a new generic parameter ValRep
for either &'a Val
or Val
, independent from the actual Val
type, which .. ) but it has been pretty gross so far.
Alternately, stick with the "they implement Clone
like all integers, and that makes everything easier. It doesn't showcase cool Rust lifetime stuff (actually cool), but it leaves the code in a much clearer state if you want Variable
treefrog impls.
I didn't see any performance difference, testing locally. If I'm not mistaken, the only real difference here in terms of the end-code is that the Val
is passed by value, right?
i.e., my "logic" closures change from |&source_tuple, &val|
to |&source_tuple, val|
?
I think i'm inclined in this case not to merge, just because the current system uses refs uniformly and that seems ultimately easier to remember.
Per prior comment, closing (at least for now).
This PR attempts to unify treefrog implementations to work both with owned and reference value types.
Previously, the signatures of the
Leaper
trait involvedLeaper<'a, Tuple, Val: 'a>
and spoke of vectors of&'a Val
elements. These references are potentially unnecessarily complicated ifVal
is simple and supports clone, so we change this to beWhere the
Val
type can be arbitrary. Now, we have multiple implementations ofLeaper
where appropriate, bothThe
FilterWith
andFilterAnti
variants had no constraint on theirVal
type, and so we just removed the requirement that it be a reference and got a more general implementation (yay). Neither looks at the value field, and just makes their decision based on the key parts of the record.The potential fall-out is that there are now multiple implementations of
Leaper
, and it may be less obvious which is intended when you casually try toleapjoin_into
.The
from_leapjoin
method onVariable
now has the signaturewhich allows
Val
to be&'a Val
as appropriate, orVal
, and it is an open question whether this will allow anyone to actually use this elegantly.