From 082d6b89ffffe1d5e30a9ddadb7d2211dec56420 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Mon, 30 May 2022 17:01:51 +0200 Subject: [PATCH] Make the StarOrIndexUid Generic and call it StarOr --- meilisearch-http/src/routes/tasks.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/meilisearch-http/src/routes/tasks.rs b/meilisearch-http/src/routes/tasks.rs index 93af5af26..a5dcc6513 100644 --- a/meilisearch-http/src/routes/tasks.rs +++ b/meilisearch-http/src/routes/tasks.rs @@ -24,24 +24,25 @@ pub struct TaskFilterQuery { #[serde(rename = "type")] type_: Option>, status: Option>, - index_uid: Option>, + index_uid: Option>>, } -/// 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)] -enum StarOrIndexUid { +enum StarOr { Star, - IndexUid(IndexUid), + Other(T), } -impl FromStr for StarOrIndexUid { - type Err = ::Err; +impl FromStr for StarOr { + type Err = T::Err; fn from_str(s: &str) -> Result { if s.trim() == "*" { - Ok(StarOrIndexUid::Star) + Ok(StarOr::Star) } 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_iter() .fold(Some(Vec::new()), |acc, val| match (acc, val) { - (None, _) | (_, StarOrIndexUid::Star) => None, - (Some(mut acc), StarOrIndexUid::IndexUid(uid)) => { + (None, _) | (_, StarOr::Star) => None, + (Some(mut acc), StarOr::Other(uid)) => { acc.push(uid); Some(acc) }