cargo fmt

This commit is contained in:
Kat Lim Ruiz
2025-03-30 22:10:38 -05:00
parent 18ae3ffe94
commit 18da402e27
4 changed files with 22 additions and 10 deletions

View File

@@ -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)),

View File

@@ -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]

View File

@@ -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.

View File

@@ -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"}}}}"#
);
}
}