implement Copy on Setting

This commit is contained in:
ad hoc 2022-03-31 18:44:51 +02:00
parent fdaf45aab2
commit 1941072bb2
No known key found for this signature in database
GPG Key ID: 4F00A782990CC643

View File

@ -14,7 +14,7 @@ use crate::update::index_documents::IndexDocumentsMethod;
use crate::update::{ClearDocuments, IndexDocuments, UpdateIndexingStep}; use crate::update::{ClearDocuments, IndexDocuments, UpdateIndexingStep};
use crate::{FieldsIdsMap, Index, Result}; use crate::{FieldsIdsMap, Index, Result};
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Copy)]
pub enum Setting<T> { pub enum Setting<T> {
Set(T), Set(T),
Reset, Reset,
@ -495,29 +495,29 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
} }
fn update_min_typo_word_len(&mut self) -> Result<()> { fn update_min_typo_word_len(&mut self) -> Result<()> {
match (&self.min_word_len_one_typo, &self.min_word_len_two_typos) { match (self.min_word_len_one_typo, self.min_word_len_two_typos) {
(Setting::Set(one), Setting::Set(two)) => { (Setting::Set(one), Setting::Set(two)) => {
if one > two { if one > two {
return Err(UserError::InvalidMinTypoWordLenSetting(*one, *two).into()); return Err(UserError::InvalidMinTypoWordLenSetting(one, two).into());
} else { } else {
self.index.put_min_word_len_one_typo(&mut self.wtxn, *one)?; self.index.put_min_word_len_one_typo(&mut self.wtxn, one)?;
self.index.put_min_word_len_two_typos(&mut self.wtxn, *two)?; self.index.put_min_word_len_two_typos(&mut self.wtxn, two)?;
} }
} }
(Setting::Set(one), _) => { (Setting::Set(one), _) => {
let two = self.index.min_word_len_two_typos(&self.wtxn)?; let two = self.index.min_word_len_two_typos(&self.wtxn)?;
if *one > two { if one > two {
return Err(UserError::InvalidMinTypoWordLenSetting(*one, two).into()); return Err(UserError::InvalidMinTypoWordLenSetting(one, two).into());
} else { } else {
self.index.put_min_word_len_one_typo(&mut self.wtxn, *one)?; self.index.put_min_word_len_one_typo(&mut self.wtxn, one)?;
} }
} }
(_, Setting::Set(two)) => { (_, Setting::Set(two)) => {
let one = self.index.min_word_len_one_typo(&self.wtxn)?; let one = self.index.min_word_len_one_typo(&self.wtxn)?;
if one > *two { if one > two {
return Err(UserError::InvalidMinTypoWordLenSetting(one, *two).into()); return Err(UserError::InvalidMinTypoWordLenSetting(one, two).into());
} else { } else {
self.index.put_min_word_len_two_typos(&mut self.wtxn, *two)?; self.index.put_min_word_len_two_typos(&mut self.wtxn, two)?;
} }
} }
_ => (), _ => (),