Closed KonradHoeffner closed 1 year ago
It seems to work with SimpleTerm::from_term(term.as_simple());
, is that the intended usage?
I'll look into it in more detail, but my first reaction is: yes, from_term
is the way to go here.
I confirm that from_term
is the way to go.
Term::as_simple
borrows the term for a lifetime 'a
and retuns a SimpleTerm<'a>
, which borrows the underlying data of the term, so can not outlive the term.
When you call SimpleTerm::from_term(t)
, you actually call SimpleTerm::<'static>::from_term(t)
, which copies the data from t
to ensures that it can live as long as 'static
.
Hope this helps.
Also, regarding the comment at the top:
/// Only supports constant and "any" matchers.
/// Non-constant matchers are supposed to be "any" matchers.
You do realize that supporting other matchers is straightforward:
Box::new(SubjectIter::with_pattern(&self.hdt.triples, &TripleId::new(s.1, 0, 0)).map(move |t| {
Ok([
s.0,
IriRef::new_unchecked(MownStr::from(
self.hdt.dict.id_to_string(t.predicate_id, &IdKind::Predicate).unwrap(),
))
.into_term(),
IriRef::new_unchecked(MownStr::from(
self.hdt.dict.id_to_string(t.object_id, &IdKind::Object).unwrap(),
))
.into_term(),
])
}) // ADD HERE:
.filter_triples(|t| pm.matches(t.p()) && om.matches(t.o()))
)
The filter_triples
should be optimized away if pm
and om
are both Any
, causing no impact on performance. That's why I got rid of all triples_with_X
variants.
Oh, I didn't realize that, thanks!
I'm trying to implement
triples_matching
for HDT but I keep gettingcannot return value referencing function parameter
errors with SimpleTerm even when I clone it or call to_owned() on it. Is there any way to convert a simple term into an owned one?