Added MultipartFile extractors.

Moved cfg macro to lib where possible.

Changed some features, and made some deps optional
This commit is contained in:
Martin Berg Alstad
2024-06-30 20:16:17 +02:00
parent e0baff8625
commit 0898a50166
17 changed files with 287 additions and 55 deletions

View File

@ -1,4 +1,3 @@
#[cfg(feature = "nom")]
use {
nom::{
bytes::complete::take_while_m_n,
@ -16,7 +15,6 @@ use {
/// - Parameters
/// - `inner`: The parser to trim
/// - Returns: A parser that trims leading and trailing whitespace from the input and then runs the value from the inner parser
#[cfg(feature = "nom")]
pub fn trim<'a, Parser, R>(inner: Parser) -> impl FnMut(&'a str) -> IResult<&'a str, R>
where
Parser: Fn(&'a str) -> IResult<&'a str, R>,
@ -29,7 +27,6 @@ where
/// - Parameters
/// - `inner`: The parser to run inside the parentheses
/// - Returns: A parser that parses a parenthesized expression
#[cfg(feature = "nom")]
pub fn parenthesized<'a, Parser, R>(inner: Parser) -> impl FnMut(&'a str) -> IResult<&'a str, R>
where
Parser: Fn(&'a str) -> IResult<&'a str, R>,
@ -42,7 +39,6 @@ where
/// - `n`: The length of the string to take
/// - `predicate`: The predicate to call to validate the input
/// - Returns: A parser that takes `n` characters from the input
#[cfg(feature = "nom")]
pub fn take_where<F, Input>(n: usize, predicate: F) -> impl Fn(Input) -> IResult<Input, Input>
where
Input: InputTake + InputIter + InputLength + Slice<RangeFrom<usize>>,
@ -51,7 +47,6 @@ where
take_while_m_n(n, n, predicate)
}
#[cfg(feature = "nom")]
pub fn exhausted<'a, Parser, R>(inner: Parser) -> impl FnMut(&'a str) -> IResult<&'a str, R>
where
Parser: Fn(&'a str) -> IResult<&'a str, R>,
@ -59,7 +54,7 @@ where
terminated(inner, eof)
}
#[cfg(all(test, feature = "nom"))]
#[cfg(test)]
mod tests {
use nom::bytes::streaming::take_while;

View File

@ -1,10 +1,8 @@
#[cfg(feature = "nom")]
use {
crate::traits::IntoResult,
nom::{error::Error, IResult},
};
#[cfg(feature = "nom")]
impl<T, R> IntoResult<T> for IResult<R, T> {
type Error = nom::Err<Error<R>>;
fn into_result(self) -> Result<T, Self::Error> {
@ -12,7 +10,7 @@ impl<T, R> IntoResult<T> for IResult<R, T> {
}
}
#[cfg(all(test, feature = "nom"))]
#[cfg(test)]
mod tests {
use nom::character::complete::char as c;