-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do a little tidying and add specific_key helper
- Loading branch information
1 parent
f04b4fa
commit 509a04c
Showing
2 changed files
with
80 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
pub mod json; | ||
|
||
use winnow::{ | ||
stream::{AsBStr, Compare, ParseSlice, Stream, StreamIsPartial}, | ||
token::take_while, | ||
PResult, Parser, | ||
}; | ||
|
||
pub trait CharStream = Stream<Token = char> + StreamIsPartial; | ||
pub trait StrStream = CharStream + for<'a> Compare<&'a str> + AsBStr | ||
where | ||
<Self as Stream>::IterOffsets: Clone, | ||
<Self as Stream>::Slice: ParseSlice<f64>; | ||
|
||
/// Characters considered whitespace for the `ws` parser. | ||
const WHITESPACE: &[char] = &[' ', '\t', '\n', '\r']; | ||
|
||
/// Parses a series of whitespace characters, returning the series as a slice. | ||
pub fn ws<S: CharStream>(buf: &mut S) -> PResult<<S as Stream>::Slice> { | ||
take_while(0.., WHITESPACE).parse_next(buf) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_ws() { | ||
assert_eq!(ws.parse_peek(" \r\t\n"), Ok(("", " \r\t\n"))); | ||
assert_eq!(ws.parse_peek(" asd"), Ok(("asd", " "))); | ||
assert_eq!(ws.parse_peek("asd "), Ok(("asd ", ""))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters