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

Generic IntoParameter on enum with value_type #1244

Open
irevoire opened this issue Dec 18, 2024 · 1 comment
Open

Generic IntoParameter on enum with value_type #1244

irevoire opened this issue Dec 18, 2024 · 1 comment

Comments

@irevoire
Copy link

Hey,

I'm coming back to integrate this awesome lib in @meilisearch; I see there have been a lot of changes since the last time I used it 🎉

I was wondering if there was a way to make that work:

/// A type representing the content of a query parameter that can either not exist, be equal to a star (*), or represent a list of other values
#[derive(Debug, Default, Clone, IntoParams)]
#[into_params(value_type = Option<Vec<T>>)]
pub enum OptionStarOrList<T> {
    #[default]
    None,
    Star,
    List(Vec<T>),
}

Context

Maybe it's the wrong thing to do, though; let me know if you have a better idea!
We use this type a lot in Meilisearch.
It's a query parameter that can be used like that:

  • Not mandatory; it's not specified /tasks
  • You use it with one value `/tasks?uid=3
  • You use it with multiple values /tasks?uid=3,4,5
  • Or you can use it with a star to match everything: /tasks?uid=*
@Jeadie
Copy link

Jeadie commented Dec 23, 2024

We have same issue with spiceai/spiceai. From what I can see, answer is no, but IntoParams can be manually implemented. This PR has an example: #680

Have not verified myself.

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

No branches or pull requests

2 participants