diff --git a/.gitignore b/.gitignore index a6ef9ef50..428b92f40 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ target/release Cargo.lock benchmark .DS_Store -cpp/simdcomp/bitpackingbenchmark \ No newline at end of file +cpp/simdcomp/bitpackingbenchmark +*.bk \ No newline at end of file diff --git a/src/core/index.rs b/src/core/index.rs index 34453adac..191fe986b 100644 --- a/src/core/index.rs +++ b/src/core/index.rs @@ -29,8 +29,7 @@ const NUM_SEARCHERS: usize = 12; fn load_metas(directory: &Directory) -> Result { let meta_data = directory.atomic_read(&META_FILEPATH)?; let meta_string = String::from_utf8_lossy(&meta_data); - serde_json::from_str(&meta_string) - .chain_err(|| ErrorKind::CorruptedFile(META_FILEPATH.clone())) + serde_json::from_str(&meta_string).chain_err(|| ErrorKind::CorruptedFile(META_FILEPATH.clone())) } /// Tantivy's Search Index diff --git a/src/directory/error.rs b/src/directory/error.rs index 4f422a198..07652daff 100644 --- a/src/directory/error.rs +++ b/src/directory/error.rs @@ -30,10 +30,7 @@ impl StdError for IOError { } impl IOError { - pub(crate) fn with_path( - path: PathBuf, - err: io::Error) - -> Self { + pub(crate) fn with_path(path: PathBuf, err: io::Error) -> Self { IOError { path: Some(path), err: err, @@ -62,8 +59,12 @@ pub enum OpenDirectoryError { impl fmt::Display for OpenDirectoryError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - OpenDirectoryError::DoesNotExist(ref path) => write!(f, "the underlying directory '{:?}' does not exist", path), - OpenDirectoryError::NotADirectory(ref path) => write!(f, "the path '{:?}' exists but is not a directory", path) + OpenDirectoryError::DoesNotExist(ref path) => { + write!(f, "the underlying directory '{:?}' does not exist", path) + } + OpenDirectoryError::NotADirectory(ref path) => { + write!(f, "the path '{:?}' exists but is not a directory", path) + } } } } @@ -98,8 +99,14 @@ impl From for OpenWriteError { impl fmt::Display for OpenWriteError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - OpenWriteError::FileAlreadyExists(ref path) => write!(f, "the file '{:?}' already exists", path), - OpenWriteError::IOError(ref err) => write!(f, "an io error occurred while opening a file for writing: '{}'", err) + OpenWriteError::FileAlreadyExists(ref path) => { + write!(f, "the file '{:?}' already exists", path) + } + OpenWriteError::IOError(ref err) => { + write!(f, + "an io error occurred while opening a file for writing: '{}'", + err) + } } } } @@ -112,7 +119,7 @@ impl StdError for OpenWriteError { fn cause(&self) -> Option<&StdError> { match *self { OpenWriteError::FileAlreadyExists(_) => None, - OpenWriteError::IOError(ref err) => Some(err) + OpenWriteError::IOError(ref err) => Some(err), } } } @@ -136,8 +143,14 @@ impl From for OpenReadError { impl fmt::Display for OpenReadError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - OpenReadError::FileDoesNotExist(ref path) => write!(f, "the file '{:?}' does not exist", path), - OpenReadError::IOError(ref err) => write!(f, "an io error occurred while opening a file for reading: '{}'", err) + OpenReadError::FileDoesNotExist(ref path) => { + write!(f, "the file '{:?}' does not exist", path) + } + OpenReadError::IOError(ref err) => { + write!(f, + "an io error occurred while opening a file for reading: '{}'", + err) + } } } } @@ -150,7 +163,7 @@ impl StdError for OpenReadError { fn cause(&self) -> Option<&StdError> { match *self { OpenReadError::FileDoesNotExist(_) => None, - OpenReadError::IOError(ref err) => Some(err) + OpenReadError::IOError(ref err) => Some(err), } } } @@ -177,9 +190,17 @@ impl From for DeleteError { impl fmt::Display for DeleteError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - DeleteError::FileDoesNotExist(ref path) => write!(f, "the file '{:?}' does not exist", path), - DeleteError::FileProtected(ref path) => write!(f, "the file '{:?}' is protected and can't be deleted", path), - DeleteError::IOError(ref err) => write!(f, "an io error occurred while opening a file for reading: '{}'", err) + DeleteError::FileDoesNotExist(ref path) => { + write!(f, "the file '{:?}' does not exist", path) + } + DeleteError::FileProtected(ref path) => { + write!(f, "the file '{:?}' is protected and can't be deleted", path) + } + DeleteError::IOError(ref err) => { + write!(f, + "an io error occurred while opening a file for reading: '{}'", + err) + } } } } @@ -191,8 +212,9 @@ impl StdError for DeleteError { fn cause(&self) -> Option<&StdError> { match *self { - DeleteError::FileDoesNotExist(_) | DeleteError::FileProtected(_) => None, - DeleteError::IOError(ref err) => Some(err) + DeleteError::FileDoesNotExist(_) | + DeleteError::FileProtected(_) => None, + DeleteError::IOError(ref err) => Some(err), } } -} \ No newline at end of file +} diff --git a/src/directory/managed_directory.rs b/src/directory/managed_directory.rs index e957bd038..04d1fd328 100644 --- a/src/directory/managed_directory.rs +++ b/src/directory/managed_directory.rs @@ -229,7 +229,8 @@ impl Directory for ManagedDirectory { } fn open_write(&mut self, path: &Path) -> result::Result { - self.register_file_as_managed(path).map_err(|e| IOError::with_path(path.to_owned(), e))?; + self.register_file_as_managed(path) + .map_err(|e| IOError::with_path(path.to_owned(), e))?; self.directory.open_write(path) } diff --git a/src/directory/mmap_directory.rs b/src/directory/mmap_directory.rs index 6e48a0078..625bae327 100644 --- a/src/directory/mmap_directory.rs +++ b/src/directory/mmap_directory.rs @@ -24,15 +24,15 @@ use std::sync::Weak; use tempdir::TempDir; fn open_mmap(full_path: &PathBuf) -> result::Result>, OpenReadError> { - let file = File::open(&full_path).map_err(|e| { - if e.kind() == io::ErrorKind::NotFound { - OpenReadError::FileDoesNotExist(full_path.clone()) - } else { - OpenReadError::IOError(IOError::with_path(full_path.to_owned(), e)) - } - })?; + let file = File::open(&full_path) + .map_err(|e| if e.kind() == io::ErrorKind::NotFound { + OpenReadError::FileDoesNotExist(full_path.clone()) + } else { + OpenReadError::IOError(IOError::with_path(full_path.to_owned(), e)) + })?; - let meta_data = file.metadata().map_err(|e| IOError::with_path(full_path.to_owned(), e))?; + let meta_data = file.metadata() + .map_err(|e| IOError::with_path(full_path.to_owned(), e))?; if meta_data.len() == 0 { // if the file size is 0, it will not be possible // to mmap the file, so we return an anonymous mmap_cache @@ -303,11 +303,13 @@ impl Directory for MmapDirectory { })?; // making sure the file is created. - file.flush().map_err(|e| IOError::with_path(path.to_owned(), e))?; + file.flush() + .map_err(|e| IOError::with_path(path.to_owned(), e))?; // Apparetntly, on some filesystem syncing the parent // directory is required. - self.sync_directory().map_err(|e| IOError::with_path(path.to_owned(), e))?; + self.sync_directory() + .map_err(|e| IOError::with_path(path.to_owned(), e))?; let writer = SafeFileWriter::new(file); Ok(BufWriter::new(Box::new(writer))) @@ -329,7 +331,10 @@ impl Directory for MmapDirectory { // when the last reference is gone. mmap_cache.cache.remove(&full_path); match fs::remove_file(&full_path) { - Ok(_) => self.sync_directory().map_err(|e| IOError::with_path(path.to_owned(), e).into()), + Ok(_) => { + self.sync_directory() + .map_err(|e| IOError::with_path(path.to_owned(), e).into()) + } Err(e) => { if e.kind() == io::ErrorKind::NotFound { Err(DeleteError::FileDoesNotExist(path.to_owned())) diff --git a/src/directory/ram_directory.rs b/src/directory/ram_directory.rs index 1deb758fc..0f205c6f1 100644 --- a/src/directory/ram_directory.rs +++ b/src/directory/ram_directory.rs @@ -164,7 +164,9 @@ impl Directory for RAMDirectory { let path_buf = PathBuf::from(path); let vec_writer = VecWriter::new(path_buf.clone(), self.fs.clone()); - let exists = self.fs.write(path_buf.clone(), &Vec::new()).map_err(|err| IOError::with_path(path.to_owned(), err))?; + let exists = self.fs + .write(path_buf.clone(), &Vec::new()) + .map_err(|err| IOError::with_path(path.to_owned(), err))?; // force the creation of the file to mimic the MMap directory. if exists { diff --git a/src/error.rs b/src/error.rs index 45fe1b017..dccb33474 100644 --- a/src/error.rs +++ b/src/error.rs @@ -116,8 +116,9 @@ impl From for Error { ErrorKind::PathDoesNotExist(directory_path).into() } OpenDirectoryError::NotADirectory(directory_path) => { - ErrorKind::InvalidArgument(format!("{:?} is not a directory", directory_path)).into() - }, + ErrorKind::InvalidArgument(format!("{:?} is not a directory", directory_path)) + .into() + } } } } diff --git a/src/indexer/index_writer.rs b/src/indexer/index_writer.rs index d291dd460..995f2f435 100644 --- a/src/indexer/index_writer.rs +++ b/src/indexer/index_writer.rs @@ -325,9 +325,9 @@ impl IndexWriter { let former_workers_handles = mem::replace(&mut self.workers_join_handle, vec![]); for join_handle in former_workers_handles { join_handle - .join() - .expect("Indexing Worker thread panicked") - .chain_err(|| ErrorKind::ErrorInThread("Error in indexing worker thread.".into()))?; + .join() + .expect("Indexing Worker thread panicked") + .chain_err(|| ErrorKind::ErrorInThread("Error in indexing worker thread.".into()))?; } drop(self.workers_join_handle); @@ -525,8 +525,8 @@ impl IndexWriter { for worker_handle in former_workers_join_handle { let indexing_worker_result = worker_handle - .join() - .map_err(|e| Error::from_kind(ErrorKind::ErrorInThread(format!("{:?}", e))))?; + .join() + .map_err(|e| Error::from_kind(ErrorKind::ErrorInThread(format!("{:?}", e))))?; indexing_worker_result?; // add a new worker for the next generation. diff --git a/src/postings/serializer.rs b/src/postings/serializer.rs index 36f489290..d5e72fa68 100644 --- a/src/postings/serializer.rs +++ b/src/postings/serializer.rs @@ -186,7 +186,8 @@ impl PostingsSerializer { // On the other hand, positions are entirely buffered until the // end of the term, at which point they are compressed and written. if self.text_indexing_options.is_position_enabled() { - self.written_bytes_positions += try!(VInt(self.position_deltas.len() as u64) + self.written_bytes_positions += + try!(VInt(self.position_deltas.len() as u64) .serialize(&mut self.positions_write)); let positions_encoded: &[u8] = self.positions_encoder .compress_unsorted(&self.position_deltas[..]); diff --git a/src/query/boolean_query/boolean_query.rs b/src/query/boolean_query/boolean_query.rs index caa47dba1..b471da320 100644 --- a/src/query/boolean_query/boolean_query.rs +++ b/src/query/boolean_query/boolean_query.rs @@ -37,8 +37,7 @@ impl Query for BooleanQuery { } fn weight(&self, searcher: &Searcher) -> Result> { - let sub_weights = - try!(self.subqueries + let sub_weights = try!(self.subqueries .iter() .map(|&(ref _occur, ref subquery)| subquery.weight(searcher)) .collect()); diff --git a/src/query/boolean_query/boolean_weight.rs b/src/query/boolean_query/boolean_weight.rs index cb3f2f4f6..04f22595c 100644 --- a/src/query/boolean_query/boolean_weight.rs +++ b/src/query/boolean_query/boolean_weight.rs @@ -22,7 +22,8 @@ impl BooleanWeight { impl Weight for BooleanWeight { fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result> { - let sub_scorers: Vec> = try!(self.weights + let sub_scorers: Vec> = + try!(self.weights .iter() .map(|weight| weight.scorer(reader)) .collect());