From 0d104a0fceab3555c5e2330ab4992d97f74d225d Mon Sep 17 00:00:00 2001 From: Irevoire Date: Mon, 20 Sep 2021 18:08:22 +0200 Subject: [PATCH] Update milli/src/criterion.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Renault --- milli/src/criterion.rs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/milli/src/criterion.rs b/milli/src/criterion.rs index eb9a6c86a..24879cdd4 100644 --- a/milli/src/criterion.rs +++ b/milli/src/criterion.rs @@ -76,23 +76,29 @@ impl FromStr for Member { type Err = UserError; fn from_str(text: &str) -> Result { - if let Some(point) = text.strip_prefix("_geoPoint(").and_then(|text| text.strip_suffix(")")) - { - let (lat, long) = point - .split_once(',') - .ok_or_else(|| UserError::InvalidRankingRuleName { name: text.to_string() }) - .and_then(|(lat, long)| { - lat.trim() - .parse() - .and_then(|lat| long.trim().parse().map(|long| (lat, long))) - .map_err(|_| UserError::InvalidRankingRuleName { name: text.to_string() }) - })?; - Ok(Member::Geo([lat, long])) - } else { - if is_reserved_keyword(text) { - return Err(UserError::InvalidReservedRankingRuleName { name: text.to_string() })?; + match text.strip_prefix("_geoPoint(").and_then(|text| text.strip_suffix(")")) { + Some(point) => { + let (lat, long) = point + .split_once(',') + .ok_or_else(|| UserError::InvalidRankingRuleName { name: text.to_string() }) + .and_then(|(lat, long)| { + lat.trim() + .parse() + .and_then(|lat| long.trim().parse().map(|long| (lat, long))) + .map_err(|_| UserError::InvalidRankingRuleName { + name: text.to_string(), + }) + })?; + Ok(Member::Geo([lat, long])) + } + None => { + if is_reserved_keyword(text) { + return Err(UserError::InvalidReservedRankingRuleName { + name: text.to_string(), + })?; + } + Ok(Member::Field(text.to_string())) } - Ok(Member::Field(text.to_string())) } } }