Rust Implementation of RSSortingVector - MOD-9985#6311
Conversation
75fb169 to
50e444c
Compare
b15859c to
a9b46e6
Compare
5d7c5d6 to
1e7e21d
Compare
08f5375 to
5f7722b
Compare
fbfddf3 to
784887d
Compare
401002e to
12e1ec8
Compare
4501bb2 to
8814717
Compare
| unimplemented!( | ||
| "We cannot yet use `NormalizedString` here, as the RSValue string allocations still happen\ | ||
| in the C layer and the workaround for linking C code for allocations is not ready." |
There was a problem hiding this comment.
| unimplemented!( | |
| "We cannot yet use `NormalizedString` here, as the RSValue string allocations still happen\ | |
| in the C layer and the workaround for linking C code for allocations is not ready." | |
| unimplemented!( | |
| "We cannot yet allocate RSValues in Rust. See MOD-10347 for details." |
| pub fn try_insert_string_for_tests<S: AsRef<str>>( | ||
| &mut self, | ||
| _idx: usize, | ||
| _str: S, | ||
| ) -> Result<(), IndexOutOfBounds> { | ||
| self.in_bounds(_idx)?; | ||
| let casemapper = CaseMapper::new(); | ||
| let normalized = casemapper.fold_string(_str.as_ref()).into_owned(); | ||
| self.values[_idx] = T::create_string(normalized); | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
Can we avoid mixing test helpers with production code?
There was a problem hiding this comment.
Due to RSValue and its C-side string allocations, this is a temporary fix. Nonetheless, I eliminated this second method.
8c2a92e to
460a463
Compare
460a463 to
3f9e3d8
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds a Rust-based RSSortingVector implementation with string normalization support, defines an RSValueTrait abstraction for value handling, and integrates C header updates and unit tests.
- Introduces
RSSortingVector<T>in Rust with methods for inserting numbers, strings (with ICU4X case folding), references, and nulls - Defines
RSValueTraitto abstract over RSValue creation and inspection for both mocks and FFI - Updates
src/sortable.hwithnormalizeStrprototype, extends the FFI build, and adds comprehensive unit tests
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/sortable.h | Added documentation and prototype for normalizeStr |
| src/redisearch_rs/value/src/lib.rs | Defined the RSValueTrait trait |
| src/redisearch_rs/value/Cargo.toml | Configured the new value crate in the workspace |
| src/redisearch_rs/sorting_vector/src/lib.rs | Implemented RSSortingVector and its APIs |
| src/redisearch_rs/sorting_vector/tests/sorting_vector.rs | Added unit tests covering creation, insertion, memory sizing, and normalization |
| src/redisearch_rs/sorting_vector/Cargo.toml | Configured the sorting_vector crate dependencies |
| src/redisearch_rs/ffi/build.rs | Included sortable.h and value.h in the bindgen build |
| src/redisearch_rs/Cargo.toml | Registered sorting_vector and value crates in the workspace |
Comments suppressed due to low confidence (3)
src/redisearch_rs/sorting_vector/src/lib.rs:79
- The doc reference
Error::OutOfBoundsdoes not match the actual error typeIndexOutOfBounds. Update the link to [IndexOutOfBounds].
/// Returns `Ok(())` if the index is in bounds, [`Error::OutOfBounds`] otherwise.
src/redisearch_rs/sorting_vector/src/lib.rs:115
- [nitpick] Parameter name
strshadows the built-instrtype. Consider renaming it (e.g.,inputorvalue) for clarity.
str: S,
src/redisearch_rs/sorting_vector/tests/sorting_vector.rs:187
- [nitpick] Variable name
strshadows the built-instrtype. Consider renaming (e.g.,input_strororiginal).
let str = "Straße";
raz-mon
left a comment
There was a problem hiding this comment.
LGTM basically
A couple of questions:
- I guess it would be good to have as full an API as possible at this point, such that we can test the most and add less additions later on when the RSValue is supported. That would basically require an extended mock for the RSValue - do you think that's worthwhile, or prefer to have bigger additions to the API and tests later on?
- Some comments relate to the previous code. While that is comfortable for the review and the transition, we should at some point remove them. Probably the best time would be prior to merging, so that we don't forget it like that.
| sz += T::mem_size(); | ||
| } | ||
|
|
||
| // the original behavior would by-pass references in the middle of the chain |
There was a problem hiding this comment.
When will the comments about the previous implementations be removed?
| } | ||
| if T::is_ptr_type() { | ||
| // count the size of the struct if not null, like in C | ||
| sz += T::mem_size(); |
There was a problem hiding this comment.
Isn't this double-counting for the second case above?
I checked the
We plan to port the
I would like to address this size calculation when we port |
raz-mon
left a comment
There was a problem hiding this comment.
LGTM
Note the rdbLoad function as well, that is not implemented here
Describe the changes in the pull request
The PR introduces two changes:
Adds
RSSortingVectorRust implementation + Unit TestsMore detailed changes
RSSortingVectoras a Boxed Slice in RustnormalizeStrwhich implements utf case folding based on nulibIRSValueTraitthat is implemented by mocks and the final FFI implementationRSValueReferenced PRs
Previous PRs:
Relies on Refactorings in: MOD-9985 Refactoring of C Code for the RSSortingVector Port #6312
Relies on API changes in: String normalization becomes caller responsibility - MOD-9985 #6426
String normalization becomes caller's responsibility in the C API for
RSSortingVectorUpcoming PRs:
Archived PRs:
Implement the new type
NormalizedStringin Rust to ensure normalized Strings inRSSortingVector