summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Masurel <paul.masurel@gmail.com>2019-08-08 18:07:19 +0900
committerPaul Masurel <paul.masurel@gmail.com>2019-08-08 18:07:19 +0900
commit001af3876fbd7a1318690d294c398b3147b6fcf2 (patch)
tree0d27f33b6943f4759f09ff638edf7e86bba87e4f
parentf428f344da427e8deb86d3e35b4f7e5bcc708624 (diff)
cargo fmt
-rw-r--r--examples/faceted_search.rs1
-rw-r--r--src/common/mod.rs19
-rw-r--r--src/directory/directory.rs4
-rw-r--r--src/directory/ram_directory.rs2
-rw-r--r--src/fastfield/writer.rs4
-rw-r--r--src/query/fuzzy_query.rs10
-rw-r--r--src/query/query_parser/query_grammar.rs2
-rw-r--r--src/query/range_query.rs5
-rw-r--r--src/schema/facet.rs4
-rw-r--r--src/schema/field_entry.rs4
-rw-r--r--src/schema/field_type.rs17
-rw-r--r--src/schema/value.rs10
12 files changed, 43 insertions, 39 deletions
diff --git a/examples/faceted_search.rs b/examples/faceted_search.rs
index 0947774..302d613 100644
--- a/examples/faceted_search.rs
+++ b/examples/faceted_search.rs
@@ -75,4 +75,3 @@ fn main() -> tantivy::Result<()> {
Ok(())
}
-
diff --git a/src/common/mod.rs b/src/common/mod.rs
index 7e41f08..b9964e1 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -124,26 +124,24 @@ pub fn f64_to_u64(val: f64) -> u64 {
/// Reverse the mapping given by [`i64_to_u64`](./fn.i64_to_u64.html).
#[inline(always)]
pub fn u64_to_f64(val: u64) -> f64 {
- f64::from_bits(
- if val & HIGHEST_BIT != 0 {
- val ^ HIGHEST_BIT
- } else {
- !val
- }
- )
+ f64::from_bits(if val & HIGHEST_BIT != 0 {
+ val ^ HIGHEST_BIT
+ } else {
+ !val
+ })
}
#[cfg(test)]
pub(crate) mod test {
pub use super::serialize::test::fixed_size_test;
- use super::{compute_num_bits, i64_to_u64, u64_to_i64, f64_to_u64, u64_to_f64};
+ use super::{compute_num_bits, f64_to_u64, i64_to_u64, u64_to_f64, u64_to_i64};
use std::f64;
fn test_i64_converter_helper(val: i64) {
assert_eq!(u64_to_i64(i64_to_u64(val)), val);
}
-
+
fn test_f64_converter_helper(val: f64) {
assert_eq!(u64_to_f64(f64_to_u64(val)), val);
}
@@ -172,7 +170,8 @@ pub(crate) mod test {
#[test]
fn test_f64_order() {
- assert!(!(f64_to_u64(f64::NEG_INFINITY)..f64_to_u64(f64::INFINITY)).contains(&f64_to_u64(f64::NAN))); //nan is not a number
+ assert!(!(f64_to_u64(f64::NEG_INFINITY)..f64_to_u64(f64::INFINITY))
+ .contains(&f64_to_u64(f64::NAN))); //nan is not a number
assert!(f64_to_u64(1.5) > f64_to_u64(1.0)); //same exponent, different mantissa
assert!(f64_to_u64(2.0) > f64_to_u64(1.0)); //same mantissa, different exponent
assert!(f64_to_u64(2.0) > f64_to_u64(1.5)); //different exponent and mantissa
diff --git a/src/directory/directory.rs b/src/directory/directory.rs
index 3e786c2..9da1cb2 100644
--- a/src/directory/directory.rs
+++ b/src/directory/directory.rs
@@ -48,14 +48,14 @@ impl RetryPolicy {
///
/// It is transparently associated to a lock file, that gets deleted
/// on `Drop.` The lock is released automatically on `Drop`.
-pub struct DirectoryLock(Box<dyn Drop + Send + Sync + 'static>);
+pub struct DirectoryLock(Box<dyn Send + Sync + 'static>);
struct DirectoryLockGuard {
directory: Box<dyn Directory>,
path: PathBuf,
}
-impl<T: Drop + Send + Sync + 'static> From<Box<T>> for DirectoryLock {
+impl<T: Send + Sync + 'static> From<Box<T>> for DirectoryLock {
fn from(underlying: Box<T>) -> Self {
DirectoryLock(underlying)
}
diff --git a/src/directory/ram_directory.rs b/src/directory/ram_directory.rs
index 2ac8626..8c6d237 100644
--- a/src/directory/ram_directory.rs
+++ b/src/directory/ram_directory.rs
@@ -177,7 +177,7 @@ impl Directory for RAMDirectory {
fn atomic_write(&mut self, path: &Path, data: &[u8]) -> io::Result<()> {
fail_point!("RAMDirectory::atomic_write", |msg| Err(io::Error::new(
io::ErrorKind::Other,
- msg.unwrap_or("Undefined".to_string())
+ msg.unwrap_or_else(|| "Undefined".to_string())
)));
let path_buf = PathBuf::from(path);
diff --git a/src/fastfield/writer.rs b/src/fastfield/writer.rs
index f1817f6..de9efe9 100644
--- a/src/fastfield/writer.rs
+++ b/src/fastfield/writer.rs
@@ -31,7 +31,9 @@ impl FastFieldsWriter {
_ => 0u64,
};
match *field_entry.field_type() {
- FieldType::I64(ref int_options) | FieldType::U64(ref int_options) | FieldType::F64(ref int_options) => {
+ FieldType::I64(ref int_options)
+ | FieldType::U64(ref int_options)
+ | FieldType::F64(ref int_options) => {
match int_options.get_fastfield_cardinality() {
Some(Cardinality::SingleValue) => {
let mut fast_field_writer = IntFastFieldWriter::new(field);
diff --git a/src/query/fuzzy_query.rs b/src/query/fuzzy_query.rs
index 1b72a32..156d7c3 100644
--- a/src/query/fuzzy_query.rs
+++ b/src/query/fuzzy_query.rs
@@ -113,12 +113,10 @@ impl FuzzyTermQuery {
let automaton = automaton_builder.build_dfa(self.term.text());
Ok(AutomatonWeight::new(self.term.field(), automaton))
}
- None => {
- return Err(InvalidArgument(format!(
- "Levenshtein distance of {} is not allowed. Choose a value in the {:?} range",
- self.distance, VALID_LEVENSHTEIN_DISTANCE_RANGE
- )))
- }
+ None => Err(InvalidArgument(format!(
+ "Levenshtein distance of {} is not allowed. Choose a value in the {:?} range",
+ self.distance, VALID_LEVENSHTEIN_DISTANCE_RANGE
+ ))),
}
}
}
diff --git a/src/query/query_parser/query_grammar.rs b/src/query/query_parser/query_grammar.rs
index a380209..51825a6 100644
--- a/src/query/query_parser/query_grammar.rs
+++ b/src/query/query_parser/query_grammar.rs
@@ -186,7 +186,7 @@ parser! {
pub fn parse_to_ast[I]()(I) -> UserInputAST
where [I: Stream<Item = char>]
{
- spaces().with(optional(ast()).skip(eof())).map(|opt_ast| opt_ast.unwrap_or(UserInputAST::empty_query()))
+ spaces().with(optional(ast()).skip(eof())).map(|opt_ast| opt_ast.unwrap_or_else(UserInputAST::empty_query))
}
}
diff --git a/src/query/range_query.rs b/src/query/range_query.rs
index 76a0c15..daaa9f2 100644
--- a/src/query/range_query.rs
+++ b/src/query/range_query.rs
@@ -460,7 +460,10 @@ mod tests {
let count_multiples =
|range_query: RangeQuery| searcher.search(&range_query, &Count).unwrap();
- assert_eq!(count_multiples(RangeQuery::new_f64(float_field, 10.0..11.0)), 9);
+ assert_eq!(
+ count_multiples(RangeQuery::new_f64(float_field, 10.0..11.0)),
+ 9
+ );
assert_eq!(
count_multiples(RangeQuery::new_f64_bounds(
float_field,
diff --git a/src/schema/facet.rs b/src/schema/facet.rs
index a77146f..7791943 100644
--- a/src/schema/facet.rs
+++ b/src/schema/facet.rs
@@ -120,9 +120,7 @@ impl Facet {
/// Extract path from the `Facet`.
pub fn to_path(&self) -> Vec<&str> {
- self.encoded_str()
- .split(|c| c == FACET_SEP_CHAR)
- .collect()
+ self.encoded_str().split(|c| c == FACET_SEP_CHAR).collect()
}
}
diff --git a/src/schema/field_entry.rs b/src/schema/field_entry.rs
index 8794e02..0c3e5f8 100644
--- a/src/schema/field_entry.rs
+++ b/src/schema/field_entry.rs
@@ -108,7 +108,9 @@ impl FieldEntry {
/// Returns true iff the field is a int (signed or unsigned) fast field
pub fn is_int_fast(&self) -> bool {
match self.field_type {
- FieldType::U64(ref options) | FieldType::I64(ref options) | FieldType::F64(ref options) => options.is_fast(),
+ FieldType::U64(ref options)
+ | FieldType::I64(ref options)
+ | FieldType::F64(ref options) => options.is_fast(),
_ => false,
}
}
diff --git a/src/schema/field_type.rs b/src/schema/field_type.rs
index 1c93ccd..bb4e935 100644
--- a/src/schema/field_type.rs
+++ b/src/schema/field_type.rs
@@ -83,9 +83,9 @@ impl FieldType {
pub fn is_indexed(&self) -> bool {
match *self {
FieldType::Str(ref text_options) => text_options.get_indexing_options().is_some(),
- FieldType::U64(ref int_options) | FieldType::I64(ref int_options) | FieldType::F64(ref int_options) => {
- int_options.is_indexed()
- }
+ FieldType::U64(ref int_options)
+ | FieldType::I64(ref int_options)
+ | FieldType::F64(ref int_options) => int_options.is_indexed(),
FieldType::Date(ref date_options) => date_options.is_indexed(),
FieldType::HierarchicalFacet => true,
FieldType::Bytes => false,
@@ -125,9 +125,12 @@ impl FieldType {
match *json {
JsonValue::String(ref field_text) => match *self {
FieldType::Str(_) => Ok(Value::Str(field_text.clone())),
- FieldType::U64(_) | FieldType::I64(_) | FieldType::F64(_) | FieldType::Date(_) => Err(
- ValueParsingError::TypeError(format!("Expected an integer, got {:?}", json)),
- ),
+ FieldType::U64(_) | FieldType::I64(_) | FieldType::F64(_) | FieldType::Date(_) => {
+ Err(ValueParsingError::TypeError(format!(
+ "Expected an integer, got {:?}",
+ json
+ )))
+ }
FieldType::HierarchicalFacet => Ok(Value::Facet(Facet::from(field_text))),
FieldType::Bytes => decode(field_text).map(Value::Bytes).map_err(|_| {
ValueParsingError::InvalidBase64(format!(
@@ -152,7 +155,7 @@ impl FieldType {
let msg = format!("Expected a u64 int, got {:?}", json);
Err(ValueParsingError::OverflowError(msg))
}
- },
+ }
FieldType::F64(_) => {
if let Some(field_val_f64) = field_val_num.as_f64() {
Ok(Value::F64(field_val_f64))
diff --git a/src/schema/value.rs b/src/schema/value.rs
index 0f3209d..8333f6a 100644
--- a/src/schema/value.rs
+++ b/src/schema/value.rs
@@ -2,7 +2,7 @@ use crate::schema::Facet;
use crate::DateTime;
use serde::de::Visitor;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
-use std::{fmt, cmp::Ordering};
+use std::{cmp::Ordering, fmt};
/// Value represents the value of a any field.
/// It is an enum over all over all of the possible field type.
@@ -27,7 +27,7 @@ pub enum Value {
impl Eq for Value {}
impl Ord for Value {
fn cmp(&self, other: &Self) -> Ordering {
- match (self,other) {
+ match (self, other) {
(Value::Str(l), Value::Str(r)) => l.cmp(r),
(Value::U64(l), Value::U64(r)) => l.cmp(r),
(Value::I64(l), Value::I64(r)) => l.cmp(r),
@@ -35,7 +35,7 @@ impl Ord for Value {
(Value::Facet(l), Value::Facet(r)) => l.cmp(r),
(Value::Bytes(l), Value::Bytes(r)) => l.cmp(r),
(Value::F64(l), Value::F64(r)) => {
- match (l.is_nan(),r.is_nan()) {
+ match (l.is_nan(), r.is_nan()) {
(false, false) => l.partial_cmp(r).unwrap(), // only fail on NaN
(true, true) => Ordering::Equal,
(true, false) => Ordering::Less, // we define NaN as less than -∞
@@ -155,7 +155,7 @@ impl Value {
Value::F64(ref value) => *value,
_ => panic!("This is not a f64 field."),
}
- }
+ }
/// Returns the Date-value, provided the value is of the `Date` type.
///
@@ -219,7 +219,7 @@ impl From<Vec<u8>> for Value {
mod binary_serialize {
use super::Value;
- use crate::common::{BinarySerializable, f64_to_u64, u64_to_f64};
+ use crate::common::{f64_to_u64, u64_to_f64, BinarySerializable};
use crate::schema::Facet;
use chrono::{TimeZone, Utc};
use std::io::{self, Read, Write};