You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Let's say you have a bunch of indices that all need pagination and sorting.
You could try to use generic structs + serdes flatten and then write a sub function that does all the sort + page query params.
Problem is you need to pass a &[&str] to the sort param. So if you have some kind of sort: Vec<String> then you have to first do sort.iter().map(|v|v.as_ref()).collect(). But this a Vec<&str>. Meaning this has to live for as long as the query exists, thus you can't do something like
fnhandle_basics(params:&BaseParams,query:&mutSearchQuery){let c:Vec<_> = params.sort_by.iter().map(|v|v.as_str()).collect();
query.sort = Some(&c);// needs &[&str]// now c would get leaked, creating a lifetime error, c's Vec has to outlive this..}fn handle_search(query:BaseParam<Entity>){letmut query =...handle_basics(¶ms,&mut query);[..]
Basic example
see above
Other
I'm not sure what the best approach is here. Only solution would be to let SeachQuery own the sort Vec. (sort: Vec<&str>)
Maybe also something like impl Iterator<T> where T: AsRef<str>.
Edit: updated variable names that I forgot to rename correctly from my MVP.
The text was updated successfully, but these errors were encountered:
0xpr03
changed the title
Sort params are hard to use
Sort params are hard to generalize
Jul 3, 2023
Description
Let's say you have a bunch of indices that all need pagination and sorting.
You could try to use generic structs + serdes flatten and then write a sub function that does all the sort + page query params.
Problem is you need to pass a
&[&str]
to the sort param. So if you have some kind ofsort: Vec<String>
then you have to first dosort.iter().map(|v|v.as_ref()).collect()
. But this a Vec<&str>. Meaning this has to live for as long as the query exists, thus you can't do something likeBasic example
see above
Other
I'm not sure what the best approach is here. Only solution would be to let SeachQuery own the sort Vec. (
sort: Vec<&str>
)Maybe also something like
impl Iterator<T> where T: AsRef<str>
.Edit: updated variable names that I forgot to rename correctly from my MVP.
The text was updated successfully, but these errors were encountered: