From 9b353dfda6bd9f4e8fa1aa4638608ce0112a4edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 30 Aug 2019 12:36:10 +0200 Subject: [PATCH] chore: Use const names to avoid typos --- meilidb-data/src/database/main_index.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/meilidb-data/src/database/main_index.rs b/meilidb-data/src/database/main_index.rs index 9718e3c96..c58b76d47 100644 --- a/meilidb-data/src/database/main_index.rs +++ b/meilidb-data/src/database/main_index.rs @@ -7,12 +7,17 @@ use crate::ranked_map::RankedMap; use super::Error; +const SCHEMA_KEY: &str = "schema"; +const WORDS_KEY: &str = "words"; +const SYNONYMS_KEY: &str = "synonyms"; +const RANKED_MAP_KEY: &str = "ranked-map"; + #[derive(Clone)] pub struct MainIndex(pub(crate) InnerRawIndex); impl MainIndex { pub fn schema(&self) -> Result, Error> { - match self.0.get_pinned("schema")? { + match self.0.get_pinned(SCHEMA_KEY)? { Some(bytes) => { let schema = Schema::read_from_bin(bytes.as_ref())?; Ok(Some(schema)) @@ -24,12 +29,12 @@ impl MainIndex { pub fn set_schema(&self, schema: &Schema) -> Result<(), Error> { let mut bytes = Vec::new(); schema.write_to_bin(&mut bytes)?; - self.0.set("schema", bytes)?; + self.0.set(SCHEMA_KEY, bytes)?; Ok(()) } pub fn words_set(&self) -> Result, Error> { - match self.0.get_pinned("words")? { + match self.0.get_pinned(WORDS_KEY)? { Some(bytes) => { let len = bytes.len(); let value = Arc::from(bytes.as_ref()); @@ -41,11 +46,11 @@ impl MainIndex { } pub fn set_words_set(&self, value: &fst::Set) -> Result<(), Error> { - self.0.set("words", value.as_fst().as_bytes()).map_err(Into::into) + self.0.set(WORDS_KEY, value.as_fst().as_bytes()).map_err(Into::into) } pub fn synonyms_set(&self) -> Result, Error> { - match self.0.get_pinned("synonyms")? { + match self.0.get_pinned(SYNONYMS_KEY)? { Some(bytes) => { let len = bytes.len(); let value = Arc::from(bytes.as_ref()); @@ -57,11 +62,11 @@ impl MainIndex { } pub fn set_synonyms_set(&self, value: &fst::Set) -> Result<(), Error> { - self.0.set("synonyms", value.as_fst().as_bytes()).map_err(Into::into) + self.0.set(SYNONYMS_KEY, value.as_fst().as_bytes()).map_err(Into::into) } pub fn ranked_map(&self) -> Result, Error> { - match self.0.get_pinned("ranked-map")? { + match self.0.get_pinned(RANKED_MAP_KEY)? { Some(bytes) => { let ranked_map = RankedMap::read_from_bin(bytes.as_ref())?; Ok(Some(ranked_map)) @@ -73,7 +78,7 @@ impl MainIndex { pub fn set_ranked_map(&self, value: &RankedMap) -> Result<(), Error> { let mut bytes = Vec::new(); value.write_to_bin(&mut bytes)?; - self.0.set("ranked-map", bytes)?; + self.0.set(RANKED_MAP_KEY, bytes)?; Ok(()) } }