Remove IndexUid::new and replace with IndexUid::from_str

This commit is contained in:
walter 2022-06-08 19:56:01 -04:00
parent ba55905377
commit 2b944ecd89
2 changed files with 3 additions and 13 deletions

View File

@ -3,6 +3,7 @@ use std::collections::BTreeMap;
use std::fmt; use std::fmt;
use std::io::Cursor; use std::io::Cursor;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
@ -23,6 +24,7 @@ use crate::dump::{self, load_dump, DumpHandler};
use crate::index::{ use crate::index::{
Checked, Document, IndexMeta, IndexStats, SearchQuery, SearchResult, Settings, Unchecked, Checked, Document, IndexMeta, IndexStats, SearchQuery, SearchResult, Settings, Unchecked,
}; };
use crate::index_resolver::error::IndexResolverError;
use crate::options::{IndexerOpts, SchedulerConfig}; use crate::options::{IndexerOpts, SchedulerConfig};
use crate::snapshot::{load_snapshot, SnapshotService}; use crate::snapshot::{load_snapshot, SnapshotService};
use crate::tasks::error::TaskError; use crate::tasks::error::TaskError;
@ -356,7 +358,7 @@ where
} }
pub async fn register_update(&self, uid: String, update: Update) -> Result<Task> { pub async fn register_update(&self, uid: String, update: Update) -> Result<Task> {
let index_uid = IndexUid::new(uid)?; let index_uid = IndexUid::from_str(&uid).map_err(IndexResolverError::from)?;
let content = match update { let content = match update {
Update::DeleteDocuments(ids) => TaskContent::DocumentDeletion { Update::DeleteDocuments(ids) => TaskContent::DocumentDeletion {
index_uid, index_uid,

View File

@ -48,18 +48,6 @@ pub fn create_index_resolver(
} }
impl IndexUid { impl IndexUid {
pub fn new(uid: String) -> Result<Self> {
if !uid
.chars()
.all(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_')
|| !(1..=400).contains(&uid.len())
{
Err(IndexResolverError::BadlyFormatted(uid))
} else {
Ok(Self(uid))
}
}
pub fn new_unchecked(s: impl AsRef<str>) -> Self { pub fn new_unchecked(s: impl AsRef<str>) -> Self {
Self(s.as_ref().to_string()) Self(s.as_ref().to_string())
} }