Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sophia 0.9 triples_matching return signature changes: best way to handle dynamic return types? #184

Open
KonradHoeffner opened this issue Nov 22, 2024 · 0 comments

Comments

@KonradHoeffner
Copy link
Contributor

KonradHoeffner commented Nov 22, 2024

Sorry if this is trivial to Rust experts but I ran into trouble refactoring the Sophia Graph implementation of HDT for the 0.9 changes so I just wanted to ask if there is an obvious solution to this:

The new return type signatures of triples and triples_matching now contain "impl Iterator<...>" but hdt_rs returns different types of Iterators depending on the pattern for triples_matching, so I have to use Box as shown below.
However the compiler now gives me warning: impl trait in impl method signature does not match trait method signature and advises me to add #[allow(refining_impl_trait)] to silence this warning.
However I'm hesitant to do that as I'm not sure if that has some negative consequences for the users. Shall I just silence the compiler or is there some other solution to this?

 fn triples_matching<'s, S, P, O>(&'s self, sm: S, pm: P, om: O) -> Box<dyn Iterator<Item=Result<Self::Triple<'s>, Self::Error>>  + 's>  
    where
        S: TermMatcher + 's,
        P: TermMatcher + 's,
        O: TermMatcher + 's,
    {
        let xso = match self.unpack_matcher(&sm, &IdKind::Subject) {
            None => return Box::new(iter::empty()),
            Some(x) => x,
        };
        [...]
        match (xso, xpo, xoo) {
            (Constant(s), Constant(p), Constant(o)) => Box::new(iter::once(Ok([s.0, p.0, o.0]))),
            (Constant(s), Constant(p), Other) => Box::new(
                SubjectIter::with_pattern(&self.hdt.triples, &TripleId::new(s.1, p.1, 0))
       [...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant