mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-04 16:22:55 +00:00
cargo fmt
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
//! nom combinators for infallible operations
|
||||
|
||||
use std::convert::Infallible;
|
||||
use serde::Serialize;
|
||||
use nom::{AsChar, IResult, InputLength, InputTakeAtPosition};
|
||||
use serde::Serialize;
|
||||
use std::convert::Infallible;
|
||||
|
||||
pub(crate) type ErrorList = Vec<LenientErrorInternal>;
|
||||
pub(crate) type JResult<I, O> = IResult<I, (O, ErrorList), Infallible>;
|
||||
@@ -44,7 +44,9 @@ fn unwrap_infallible<T>(res: Result<T, nom::Err<Infallible>>) -> T {
|
||||
///
|
||||
/// It's less generic than the original to ease type resolution in the rest of the code.
|
||||
pub(crate) fn opt_i<I: Clone, O, F>(mut f: F) -> impl FnMut(I) -> JResult<I, Option<O>>
|
||||
where F: nom::Parser<I, O, nom::error::Error<I>> {
|
||||
where
|
||||
F: nom::Parser<I, O, nom::error::Error<I>>,
|
||||
{
|
||||
move |input: I| {
|
||||
let i = input.clone();
|
||||
match f.parse(input) {
|
||||
@@ -104,7 +106,9 @@ where
|
||||
pub(crate) fn fallible<I, O, E: nom::error::ParseError<I>, F>(
|
||||
mut f: F,
|
||||
) -> impl FnMut(I) -> IResult<I, O, E>
|
||||
where F: nom::Parser<I, (O, ErrorList), Infallible> {
|
||||
where
|
||||
F: nom::Parser<I, (O, ErrorList), Infallible>,
|
||||
{
|
||||
use nom::Err;
|
||||
move |input: I| match f.parse(input) {
|
||||
Ok((input, (output, _err))) => Ok((input, output)),
|
||||
|
||||
@@ -26,7 +26,6 @@ pub fn parse_query_lenient(query: &str) -> (UserInputAst, Vec<LenientError>) {
|
||||
parse_to_ast_lenient(query)
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{parse_query, parse_query_lenient};
|
||||
@@ -35,7 +34,10 @@ mod tests {
|
||||
fn test_parse_query_serialization() {
|
||||
let ast = parse_query("title:hello").unwrap();
|
||||
let json = serde_json::to_string(&ast).unwrap();
|
||||
assert_eq!(json, r#"{"Leaf":{"Literal":{"field_name":"title","phrase":"hello","delimiter":"None","slop":0,"prefix":false}}}"#);
|
||||
assert_eq!(
|
||||
json,
|
||||
r#"{"Leaf":{"Literal":{"field_name":"title","phrase":"hello","delimiter":"None","slop":0,"prefix":false}}}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
use std::fmt::Write;
|
||||
use serde::{Serialize};
|
||||
|
||||
/// Defines whether a term in a query must be present,
|
||||
/// should be present or must not be present.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use serde::{Serialize};
|
||||
|
||||
use crate::Occur;
|
||||
|
||||
@@ -309,7 +309,10 @@ mod tests {
|
||||
};
|
||||
let ast = UserInputAst::Leaf(Box::new(UserInputLeaf::Literal(literal)));
|
||||
let json = serde_json::to_string(&ast).unwrap();
|
||||
assert_eq!(json, r#"{"Leaf":{"Literal":{"field_name":"title","phrase":"hello","delimiter":"None","slop":0,"prefix":false}}}"#);
|
||||
assert_eq!(
|
||||
json,
|
||||
r#"{"Leaf":{"Literal":{"field_name":"title","phrase":"hello","delimiter":"None","slop":0,"prefix":false}}}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -321,6 +324,9 @@ mod tests {
|
||||
};
|
||||
let ast = UserInputAst::Leaf(Box::new(range));
|
||||
let json = serde_json::to_string(&ast).unwrap();
|
||||
assert_eq!(json, r#"{"Leaf":{"Range":{"field":"price","lower":{"Inclusive":"10"},"upper":{"Exclusive":"100"}}}}"#);
|
||||
assert_eq!(
|
||||
json,
|
||||
r#"{"Leaf":{"Range":{"field":"price","lower":{"Inclusive":"10"},"upper":{"Exclusive":"100"}}}}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user