mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-25 22:34:28 +01:00
Make the StarOrIndexUid Generic and call it StarOr
This commit is contained in:
parent
b82c86c8f5
commit
082d6b89ff
@ -24,24 +24,25 @@ pub struct TaskFilterQuery {
|
|||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
type_: Option<CS<TaskType>>,
|
type_: Option<CS<TaskType>>,
|
||||||
status: Option<CS<TaskStatus>>,
|
status: Option<CS<TaskStatus>>,
|
||||||
index_uid: Option<CS<StarOrIndexUid>>,
|
index_uid: Option<CS<StarOr<IndexUid>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type that tries to match either a star (*) or an IndexUid.
|
/// A type that tries to match either a star (*) or
|
||||||
|
/// any other thing that implements `FromStr`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum StarOrIndexUid {
|
enum StarOr<T> {
|
||||||
Star,
|
Star,
|
||||||
IndexUid(IndexUid),
|
Other(T),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for StarOrIndexUid {
|
impl<T: FromStr> FromStr for StarOr<T> {
|
||||||
type Err = <IndexUid as FromStr>::Err;
|
type Err = T::Err;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
if s.trim() == "*" {
|
if s.trim() == "*" {
|
||||||
Ok(StarOrIndexUid::Star)
|
Ok(StarOr::Star)
|
||||||
} else {
|
} else {
|
||||||
IndexUid::from_str(s).map(StarOrIndexUid::IndexUid)
|
T::from_str(s).map(StarOr::Other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,8 +99,8 @@ async fn get_tasks(
|
|||||||
.into_inner()
|
.into_inner()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.fold(Some(Vec::new()), |acc, val| match (acc, val) {
|
.fold(Some(Vec::new()), |acc, val| match (acc, val) {
|
||||||
(None, _) | (_, StarOrIndexUid::Star) => None,
|
(None, _) | (_, StarOr::Star) => None,
|
||||||
(Some(mut acc), StarOrIndexUid::IndexUid(uid)) => {
|
(Some(mut acc), StarOr::Other(uid)) => {
|
||||||
acc.push(uid);
|
acc.push(uid);
|
||||||
Some(acc)
|
Some(acc)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user