From 9e1eb252326aca7dea98ac1178ffa663f1548517 Mon Sep 17 00:00:00 2001 From: mpostma Date: Fri, 5 Mar 2021 19:54:46 +0100 Subject: [PATCH 1/2] implement display for criterion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update milli/src/criterion.rs Co-authored-by: Clément Renault --- milli/src/criterion.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/milli/src/criterion.rs b/milli/src/criterion.rs index ead5b9da3..e9f5f87ca 100644 --- a/milli/src/criterion.rs +++ b/milli/src/criterion.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::fmt; use anyhow::{Context, bail}; use regex::Regex; @@ -63,3 +64,20 @@ pub fn default_criteria() -> Vec { Criterion::Exactness, ] } + +impl fmt::Display for Criterion { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use Criterion::*; + + match self { + Typo => f.write_str("typo"), + Words => f.write_str("words"), + Proximity => f.write_str("proximity"), + Attribute => f.write_str("attribute"), + WordsPosition => f.write_str("wordsPosition"), + Exactness => f.write_str("exactness"), + Asc(attr) => write!(f, "asc({:?})", attr), + Desc(attr) => write!(f, "desc({:?})", attr), + } + } +} From e3095be85c20f3c773633345bfc655fee5f25233 Mon Sep 17 00:00:00 2001 From: mpostma Date: Mon, 8 Mar 2021 12:09:09 +0100 Subject: [PATCH 2/2] Remove Debug use in Display impl --- milli/src/criterion.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/milli/src/criterion.rs b/milli/src/criterion.rs index e9f5f87ca..5d8ba09ba 100644 --- a/milli/src/criterion.rs +++ b/milli/src/criterion.rs @@ -76,8 +76,8 @@ impl fmt::Display for Criterion { Attribute => f.write_str("attribute"), WordsPosition => f.write_str("wordsPosition"), Exactness => f.write_str("exactness"), - Asc(attr) => write!(f, "asc({:?})", attr), - Desc(attr) => write!(f, "desc({:?})", attr), + Asc(attr) => write!(f, "asc({})", attr), + Desc(attr) => write!(f, "desc({})", attr), } } }