winnow::ascii

Struct Caseless

Source
pub struct Caseless<T>(pub T);
Expand description

Mark a value as case-insensitive for ASCII characters

§Example


fn parser<'s>(s: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
  Caseless("hello").parse_next(s)
}

assert_eq!(parser.parse_peek("Hello, World!"), Ok((", World!", "Hello")));
assert_eq!(parser.parse_peek("hello, World!"), Ok((", World!", "hello")));
assert_eq!(parser.parse_peek("HeLlo, World!"), Ok((", World!", "HeLlo")));
assert_eq!(parser.parse_peek("Some"), Err(ErrMode::Backtrack(InputError::new("Some", ErrorKind::Tag))));
assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));

Tuple Fields§

§0: T

Implementations§

Source§

impl Caseless<&str>

Source

pub fn as_bytes(&self) -> Caseless<&[u8]>

Get the byte-representation of this case-insensitive value

Trait Implementations§

Source§

impl<T: Clone> Clone for Caseless<T>

Source§

fn clone(&self) -> Caseless<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, 'b> Compare<Caseless<&'b [u8]>> for &'a [u8]

Source§

fn compare(&self, t: AsciiCaseless<&'b [u8]>) -> CompareResult

Compares self to another value for equality
Source§

impl<'a, 'b, const LEN: usize> Compare<Caseless<&'b [u8; LEN]>> for &'a [u8]

Source§

fn compare(&self, t: AsciiCaseless<&'b [u8; LEN]>) -> CompareResult

Compares self to another value for equality
Source§

impl<'a, 'b> Compare<Caseless<&'b str>> for &'a [u8]

Source§

fn compare(&self, t: AsciiCaseless<&'b str>) -> CompareResult

Compares self to another value for equality
Source§

impl<'a, 'b> Compare<Caseless<&'b str>> for &'a str

Source§

fn compare(&self, t: AsciiCaseless<&'b str>) -> CompareResult

Compares self to another value for equality
Source§

impl<'a, const LEN: usize> Compare<Caseless<[u8; LEN]>> for &'a [u8]

Source§

fn compare(&self, t: AsciiCaseless<[u8; LEN]>) -> CompareResult

Compares self to another value for equality
Source§

impl<'a> Compare<Caseless<char>> for &'a [u8]

Source§

fn compare(&self, t: AsciiCaseless<char>) -> CompareResult

Compares self to another value for equality
Source§

impl<'a> Compare<Caseless<char>> for &'a str

Source§

fn compare(&self, t: AsciiCaseless<char>) -> CompareResult

Compares self to another value for equality
Source§

impl<'a> Compare<Caseless<u8>> for &'a [u8]

Source§

fn compare(&self, t: AsciiCaseless<u8>) -> CompareResult

Compares self to another value for equality
Source§

impl<T: Debug> Debug for Caseless<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'s, I, E: ParserError<I>> Parser<I, <I as Stream>::Slice, E> for Caseless<&'s [u8]>
where I: Compare<Caseless<&'s [u8]>> + StreamIsPartial + Stream,

This is a shortcut for literal.

§Example

use winnow::ascii::Caseless;

fn parser<'s>(s: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> {
  alt((Caseless(&"hello"[..]), take(5usize))).parse_next(s)
}

assert_eq!(parser.parse_peek(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
assert_eq!(parser.parse_peek(&b"hello, World!"[..]), Ok((&b", World!"[..], &b"hello"[..])));
assert_eq!(parser.parse_peek(&b"HeLlo, World!"[..]), Ok((&b", World!"[..], &b"HeLlo"[..])));
assert_eq!(parser.parse_peek(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
assert_eq!(parser.parse_peek(&b"Some"[..]), Err(ErrMode::Backtrack(InputError::new(&b"Some"[..], ErrorKind::Slice))));
assert_eq!(parser.parse_peek(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&b""[..], ErrorKind::Slice))));
Source§

fn parse_next(&mut self, i: &mut I) -> PResult<<I as Stream>::Slice, E>

Take tokens from the Stream, turning it into the output Read more
Source§

fn parse(&mut self, input: I) -> Result<O, ParseError<I, E>>
where Self: Sized, I: Stream + StreamIsPartial, E: ParserError<I>,

Parse all of input, generating O from it
Source§

fn parse_peek(&mut self, input: I) -> IResult<I, O, E>

Take tokens from the Stream, turning it into the output Read more
Source§

fn by_ref(&mut self) -> ByRef<'_, Self>
where Self: Sized,

Treat &mut Self as a parser Read more
Source§

fn value<O2>(self, val: O2) -> Value<Self, I, O, O2, E>
where Self: Sized, O2: Clone,

Produce the provided value Read more
Source§

fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
where Self: Sized, O2: Default,

Produce a type’s default value Read more
Source§

fn void(self) -> Void<Self, I, O, E>
where Self: Sized,

Discards the output of the Parser Read more
Source§

fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
where Self: Sized, O: Into<O2>,

Convert the parser’s output to another type using std::convert::From Read more
Source§

fn take(self) -> Take<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input as produced value. Read more
Source§

fn recognize(self) -> Take<Self, I, O, E>
where Self: Sized, I: Stream,

👎Deprecated since 0.6.14: Replaced with Parser::take
Replaced with Parser::take
Source§

fn with_taken(self) -> WithTaken<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input with the output Read more
Source§

fn with_recognized(self) -> WithTaken<Self, I, O, E>
where Self: Sized, I: Stream,

👎Deprecated since 0.6.14: Replaced with Parser::with_taken
Replaced with Parser::with_taken
Source§

fn span(self) -> Span<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of the consumed input as produced value. Read more
Source§

fn with_span(self) -> WithSpan<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of consumed input with the output Read more
Source§

fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
where G: FnMut(O) -> O2, Self: Sized,

Maps a function over the output of a parser Read more
Source§

fn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
where Self: Sized, G: FnMut(O) -> Result<O2, E2>, I: Stream, E: FromExternalError<I, E2>,

Applies a function returning a Result over the output of a parser. Read more
Source§

fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> Option<O2>, I: Stream, E: ParserError<I>,

Source§

fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> H, H: Parser<I, O2, E>,

Creates a parser from the output of this one Read more
Source§

fn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>
where Self: Sized, G: Parser<O, O2, E>, O: StreamIsPartial, I: Stream,

Applies a second parser over the output of the first one Read more
Source§

fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
where Self: Sized, I: Stream, O: ParseSlice<O2>, E: ParserError<I>,

Apply std::str::FromStr to the output of the parser Read more
Source§

fn verify<G, O2>(self, filter: G) -> Verify<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(&O2) -> bool, I: Stream, O: Borrow<O2>, O2: ?Sized, E: ParserError<I>,

Returns the output of the child parser if it satisfies a verification function. Read more
Source§

fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
where Self: Sized, I: Stream, E: AddContext<I, C>, C: Clone + Debug,

If parsing fails, add context to the error Read more
Source§

fn complete_err(self) -> CompleteErr<Self>
where Self: Sized,

Source§

fn err_into<E2>(self) -> ErrInto<Self, I, O, E, E2>
where Self: Sized, E: Into<E2>,

Convert the parser’s error to another type using std::convert::From
Source§

impl<'s, I, E: ParserError<I>, const N: usize> Parser<I, <I as Stream>::Slice, E> for Caseless<&'s [u8; N]>
where I: Compare<Caseless<&'s [u8; N]>> + StreamIsPartial + Stream,

This is a shortcut for literal.

§Example

use winnow::ascii::Caseless;

fn parser<'s>(s: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> {
  alt((Caseless(b"hello"), take(5usize))).parse_next(s)
}

assert_eq!(parser.parse_peek(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
assert_eq!(parser.parse_peek(&b"hello, World!"[..]), Ok((&b", World!"[..], &b"hello"[..])));
assert_eq!(parser.parse_peek(&b"HeLlo, World!"[..]), Ok((&b", World!"[..], &b"HeLlo"[..])));
assert_eq!(parser.parse_peek(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
assert_eq!(parser.parse_peek(&b"Some"[..]), Err(ErrMode::Backtrack(InputError::new(&b"Some"[..], ErrorKind::Slice))));
assert_eq!(parser.parse_peek(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&b""[..], ErrorKind::Slice))));
Source§

fn parse_next(&mut self, i: &mut I) -> PResult<<I as Stream>::Slice, E>

Take tokens from the Stream, turning it into the output Read more
Source§

fn parse(&mut self, input: I) -> Result<O, ParseError<I, E>>
where Self: Sized, I: Stream + StreamIsPartial, E: ParserError<I>,

Parse all of input, generating O from it
Source§

fn parse_peek(&mut self, input: I) -> IResult<I, O, E>

Take tokens from the Stream, turning it into the output Read more
Source§

fn by_ref(&mut self) -> ByRef<'_, Self>
where Self: Sized,

Treat &mut Self as a parser Read more
Source§

fn value<O2>(self, val: O2) -> Value<Self, I, O, O2, E>
where Self: Sized, O2: Clone,

Produce the provided value Read more
Source§

fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
where Self: Sized, O2: Default,

Produce a type’s default value Read more
Source§

fn void(self) -> Void<Self, I, O, E>
where Self: Sized,

Discards the output of the Parser Read more
Source§

fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
where Self: Sized, O: Into<O2>,

Convert the parser’s output to another type using std::convert::From Read more
Source§

fn take(self) -> Take<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input as produced value. Read more
Source§

fn recognize(self) -> Take<Self, I, O, E>
where Self: Sized, I: Stream,

👎Deprecated since 0.6.14: Replaced with Parser::take
Replaced with Parser::take
Source§

fn with_taken(self) -> WithTaken<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input with the output Read more
Source§

fn with_recognized(self) -> WithTaken<Self, I, O, E>
where Self: Sized, I: Stream,

👎Deprecated since 0.6.14: Replaced with Parser::with_taken
Replaced with Parser::with_taken
Source§

fn span(self) -> Span<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of the consumed input as produced value. Read more
Source§

fn with_span(self) -> WithSpan<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of consumed input with the output Read more
Source§

fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
where G: FnMut(O) -> O2, Self: Sized,

Maps a function over the output of a parser Read more
Source§

fn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
where Self: Sized, G: FnMut(O) -> Result<O2, E2>, I: Stream, E: FromExternalError<I, E2>,

Applies a function returning a Result over the output of a parser. Read more
Source§

fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> Option<O2>, I: Stream, E: ParserError<I>,

Source§

fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> H, H: Parser<I, O2, E>,

Creates a parser from the output of this one Read more
Source§

fn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>
where Self: Sized, G: Parser<O, O2, E>, O: StreamIsPartial, I: Stream,

Applies a second parser over the output of the first one Read more
Source§

fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
where Self: Sized, I: Stream, O: ParseSlice<O2>, E: ParserError<I>,

Apply std::str::FromStr to the output of the parser Read more
Source§

fn verify<G, O2>(self, filter: G) -> Verify<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(&O2) -> bool, I: Stream, O: Borrow<O2>, O2: ?Sized, E: ParserError<I>,

Returns the output of the child parser if it satisfies a verification function. Read more
Source§

fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
where Self: Sized, I: Stream, E: AddContext<I, C>, C: Clone + Debug,

If parsing fails, add context to the error Read more
Source§

fn complete_err(self) -> CompleteErr<Self>
where Self: Sized,

Source§

fn err_into<E2>(self) -> ErrInto<Self, I, O, E, E2>
where Self: Sized, E: Into<E2>,

Convert the parser’s error to another type using std::convert::From
Source§

impl<'s, I, E: ParserError<I>> Parser<I, <I as Stream>::Slice, E> for Caseless<&'s str>

This is a shortcut for literal.

§Example


fn parser<'s>(s: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
  alt((Caseless("hello"), take(5usize))).parse_next(s)
}

assert_eq!(parser.parse_peek("Hello, World!"), Ok((", World!", "Hello")));
assert_eq!(parser.parse_peek("hello, World!"), Ok((", World!", "hello")));
assert_eq!(parser.parse_peek("HeLlo, World!"), Ok((", World!", "HeLlo")));
assert_eq!(parser.parse_peek("Something"), Ok(("hing", "Somet")));
assert_eq!(parser.parse_peek("Some"), Err(ErrMode::Backtrack(InputError::new("Some", ErrorKind::Slice))));
assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
Source§

fn parse_next(&mut self, i: &mut I) -> PResult<<I as Stream>::Slice, E>

Take tokens from the Stream, turning it into the output Read more
Source§

fn parse(&mut self, input: I) -> Result<O, ParseError<I, E>>
where Self: Sized, I: Stream + StreamIsPartial, E: ParserError<I>,

Parse all of input, generating O from it
Source§

fn parse_peek(&mut self, input: I) -> IResult<I, O, E>

Take tokens from the Stream, turning it into the output Read more
Source§

fn by_ref(&mut self) -> ByRef<'_, Self>
where Self: Sized,

Treat &mut Self as a parser Read more
Source§

fn value<O2>(self, val: O2) -> Value<Self, I, O, O2, E>
where Self: Sized, O2: Clone,

Produce the provided value Read more
Source§

fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
where Self: Sized, O2: Default,

Produce a type’s default value Read more
Source§

fn void(self) -> Void<Self, I, O, E>
where Self: Sized,

Discards the output of the Parser Read more
Source§

fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
where Self: Sized, O: Into<O2>,

Convert the parser’s output to another type using std::convert::From Read more
Source§

fn take(self) -> Take<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input as produced value. Read more
Source§

fn recognize(self) -> Take<Self, I, O, E>
where Self: Sized, I: Stream,

👎Deprecated since 0.6.14: Replaced with Parser::take
Replaced with Parser::take
Source§

fn with_taken(self) -> WithTaken<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input with the output Read more
Source§

fn with_recognized(self) -> WithTaken<Self, I, O, E>
where Self: Sized, I: Stream,

👎Deprecated since 0.6.14: Replaced with Parser::with_taken
Replaced with Parser::with_taken
Source§

fn span(self) -> Span<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of the consumed input as produced value. Read more
Source§

fn with_span(self) -> WithSpan<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of consumed input with the output Read more
Source§

fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
where G: FnMut(O) -> O2, Self: Sized,

Maps a function over the output of a parser Read more
Source§

fn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
where Self: Sized, G: FnMut(O) -> Result<O2, E2>, I: Stream, E: FromExternalError<I, E2>,

Applies a function returning a Result over the output of a parser. Read more
Source§

fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> Option<O2>, I: Stream, E: ParserError<I>,

Source§

fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> H, H: Parser<I, O2, E>,

Creates a parser from the output of this one Read more
Source§

fn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>
where Self: Sized, G: Parser<O, O2, E>, O: StreamIsPartial, I: Stream,

Applies a second parser over the output of the first one Read more
Source§

fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
where Self: Sized, I: Stream, O: ParseSlice<O2>, E: ParserError<I>,

Apply std::str::FromStr to the output of the parser Read more
Source§

fn verify<G, O2>(self, filter: G) -> Verify<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(&O2) -> bool, I: Stream, O: Borrow<O2>, O2: ?Sized, E: ParserError<I>,

Returns the output of the child parser if it satisfies a verification function. Read more
Source§

fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
where Self: Sized, I: Stream, E: AddContext<I, C>, C: Clone + Debug,

If parsing fails, add context to the error Read more
Source§

fn complete_err(self) -> CompleteErr<Self>
where Self: Sized,

Source§

fn err_into<E2>(self) -> ErrInto<Self, I, O, E, E2>
where Self: Sized, E: Into<E2>,

Convert the parser’s error to another type using std::convert::From
Source§

impl<S: SliceLen> SliceLen for Caseless<S>

Source§

fn slice_len(&self) -> usize

Calculates the input length, as indicated by its name, and the name of the trait itself
Source§

impl<T: Copy> Copy for Caseless<T>

Auto Trait Implementations§

§

impl<T> Freeze for Caseless<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Caseless<T>
where T: RefUnwindSafe,

§

impl<T> Send for Caseless<T>
where T: Send,

§

impl<T> Sync for Caseless<T>
where T: Sync,

§

impl<T> Unpin for Caseless<T>
where T: Unpin,

§

impl<T> UnwindSafe for Caseless<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.