support for comparators as closures #765
Merged
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.
I have updated the code for supporting comparators as closures.
Reason for this is that moving from functions to closures makes it possible to add more information into the comparator function. Let us for example say one is creating a sql-base and then would like to add a compound index, based on the create index statement. The sort order in the comparator should then depend on the directions of the sorting fields, for example first sort on a float and then an int.
The old solution did not support a way to add meta-info like this into the compare function in a dynamical way and this is currently solved by allowing the comparator to be a closure. By using the move-functionality with closures we can add extra context to the compare function.
The solution is backwards compatible, as it still supports functions as these can be casted to closures in Rust.
I have also added a test-file for comparators where I test backwards compatiblity, and the new solution with support for closures.
Feel free to drop a line to me on petter.egesund@gmail.com if you would like to discuss.