Combine Query
and QueryLens
using a type parameter for state, but don't introduce owned iterators
#19787
+673
−582
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Make
QueryLens
easier to use by allowing query methods to be called on it directly instead of needing to call thequery()
method first.Split out from #18162. I thought this might be easier to review separately, but if we do merge #18162 then this PR will no longer be necessary.
Solution
Make
Query
and the various iterator types generic, where normal queries use borrowed&QueryState<D, F>
andQueryLens
uses ownedBox<QueryState<D, F>>
.Have
Query
use a default type for the state so that it continues to work without specifying it explicitly.Note that the
'state
lifetime onQuery
was only used in&'state QueryState
, so it is now only used in the default type parameter. It still needs to be part of theQuery
type in order to be referenced in the default type, so we need aPhantomData
so that it's actually used.Testing
I used
cargo-show-asm
to verify that the assembly ofQuery::iter
did not change.This rust code:
Run with
Results in the same asm before and after the change