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

Introduce a SearchIndex trait and SearchIndexWithLocate trait. #49

Closed
wants to merge 1 commit into from

Conversation

faassen
Copy link
Collaborator

@faassen faassen commented Jan 30, 2025

These are intended to be the generic public API. FMIndexBackend is now not intended to be used in the public API at all, though it's still exposed to it because the SearchIndex trait depends on it.

The SearchIndex and SearchIndexWithLocate traits are object-safe, i.e. they're compatible with dyn. The idea is that we can then use a builder that produces a Box, as this is required to support a dynamic builder that picks the backend based on the builder parameters. I haven't implemented this new builder yet, but this is a prerequisite for that.

Unfortunately to make SearchIndex object-safe I can't use the generic K argument to search anymore. This is used to easily take an AsRef and is especially useful when you pass in a string. I've instead come up with a solution using dyn, which has some performance overhead but I suspect it's really tiny so we should be okay.

That solution is not the exact equivalent of AsRef; you have to manually & the string to make a reference to make it work. I think that's acceptable enough.

These are intended to be the generic public API. FMIndexBackend is now not
intended to be used in the public API at all, though it's still exposed to it because
the SearchIndex trait depends on it.

The SearchIndex and SearchIndexWithLocate traits are object-safe, i.e. they're compatible
with dyn. The idea is that we can then use a builder that produces a Box<dyn SearchIndex>, as this is
required to support a dynamic builder that picks the backend based on the builder parameters. I haven't
implemented this new builder yet, but this is a prerequisite for that.

Unfortunately to make SearchIndex object-safe I can't use the generic K argument to `search` anymore. This
is used to easily take an AsRef and is especially useful when you pass in a string. I've instead come up
with a solution using dyn, which has some performance overhead but I suspect it's really tiny so we should be okay.

That solution is not the exact equivalent of AsRef; you have to manually `&` the string to make a reference to make it
work. I think that's acceptable enough.
@faassen faassen requested a review from ajalab January 30, 2025 14:48
@faassen
Copy link
Collaborator Author

faassen commented Jan 30, 2025

I am going to hold off merging this one. I think in the end we need an approach quite similar to the previous work I did to avoid exposing the backend, but I think I will continue this tomorrow.

@faassen faassen marked this pull request as draft January 31, 2025 09:48
@faassen
Copy link
Collaborator Author

faassen commented Jan 31, 2025

I'm closing this one as the branch is a bit misnamed now (it's not necessarily dyn compatible). I'm going to put up another draft PR for my latest work.

@faassen faassen closed this Jan 31, 2025
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

Successfully merging this pull request may close these issues.

1 participant