Skip to content

Commit

Permalink
fix(token)!: Dont require SliceLen for literal
Browse files Browse the repository at this point in the history
This makes it easier to use `literal` with more types.
I also expect this doesn't lose out on much as `Needed` for a literal is
not likely to report the actual number of needed tokens but a small
amount for the next batch, likely too small to be worth trying to fetch
an exact amount.
  • Loading branch information
epage committed Jan 28, 2025
1 parent b6a24f7 commit b901b47
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 152 deletions.
8 changes: 4 additions & 4 deletions src/ascii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Caseless<&str> {
/// # use winnow::ascii::crlf;
/// assert_eq!(crlf::<_, ErrMode<ContextError>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
/// assert!(crlf::<_, ErrMode<ContextError>>.parse_peek(Partial::new("ab\r\nc")).is_err());
/// assert_eq!(crlf::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(2))));
/// assert_eq!(crlf::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// ```
#[inline(always)]
pub fn crlf<Input, Error>(input: &mut Input) -> Result<<Input as Stream>::Slice, Error>
Expand Down Expand Up @@ -239,7 +239,7 @@ where
/// # use winnow::ascii::line_ending;
/// assert_eq!(line_ending::<_, ErrMode<ContextError>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
/// assert!(line_ending::<_, ErrMode<ContextError>>.parse_peek(Partial::new("ab\r\nc")).is_err());
/// assert_eq!(line_ending::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// assert_eq!(line_ending::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// ```
#[inline(always)]
pub fn line_ending<Input, Error>(input: &mut Input) -> Result<<Input as Stream>::Slice, Error>
Expand Down Expand Up @@ -288,7 +288,7 @@ where
/// # use winnow::ascii::newline;
/// assert_eq!(newline::<_, ErrMode<ContextError>>.parse_peek(Partial::new("\nc")), Ok((Partial::new("c"), '\n')));
/// assert!(newline::<_, ErrMode<ContextError>>.parse_peek(Partial::new("\r\nc")).is_err());
/// assert_eq!(newline::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// assert_eq!(newline::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// ```
#[inline(always)]
pub fn newline<I, Error: ParserError<I>>(input: &mut I) -> Result<char, Error>
Expand Down Expand Up @@ -338,7 +338,7 @@ where
/// # use winnow::ascii::tab;
/// assert_eq!(tab::<_, ErrMode<ContextError>>.parse_peek(Partial::new("\tc")), Ok((Partial::new("c"), '\t')));
/// assert!(tab::<_, ErrMode<ContextError>>.parse_peek(Partial::new("\r\nc")).is_err());
/// assert_eq!(tab::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// assert_eq!(tab::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// ```
#[inline(always)]
pub fn tab<Input, Error>(input: &mut Input) -> Result<char, Error>
Expand Down
16 changes: 4 additions & 12 deletions src/ascii/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4190,9 +4190,7 @@ Ok(
str![[r#"
Err(
Incomplete(
Size(
1,
),
Unknown,
),
)
Expand Down Expand Up @@ -4242,9 +4240,7 @@ Ok(
str![[r#"
Err(
Incomplete(
Size(
1,
),
Unknown,
),
)
Expand Down Expand Up @@ -4319,9 +4315,7 @@ Ok(
str![[r#"
Err(
Incomplete(
Size(
1,
),
Unknown,
),
)
Expand Down Expand Up @@ -4387,9 +4381,7 @@ Ok(
str![[r#"
Err(
Incomplete(
Size(
1,
),
Unknown,
),
)
Expand Down
8 changes: 2 additions & 6 deletions src/binary/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3212,9 +3212,7 @@ Ok(
str![[r#"
Err(
Incomplete(
Size(
1,
),
Unknown,
),
)
Expand All @@ -3226,9 +3224,7 @@ Err(
str![[r#"
Err(
Incomplete(
Size(
1,
),
Unknown,
),
)
Expand Down
Loading

0 comments on commit b901b47

Please sign in to comment.