Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"
documentation = "https://docs.rs/nom-bufreader"

[dependencies]
nom = "7.0.0"
nom = "8.0.0"
async-trait = { version = "0.1.51", optional = true }
futures = { version = "0.3.16", optional = true }
pin-project-lite = { version = "0.2.7", optional = true }
Expand Down
7 changes: 4 additions & 3 deletions examples/async_std_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use nom::{
bytes::streaming::{tag, take_until},
character::streaming::space0,
combinator::map_res,
IResult,
IResult, Parser,
};
use nom_bufreader::async_bufreader::BufReader;
use nom_bufreader::{AsyncParse, Error};
Expand All @@ -12,11 +12,12 @@ use std::str::from_utf8;
fn method(i: &[u8]) -> IResult<&[u8], String, ()> {
map_res(alt((tag("GET"), tag("POST"), tag("HEAD"))), |s| {
from_utf8(s).map(|s| s.to_string())
})(i)
})
.parse(i)
}

fn path(i: &[u8]) -> IResult<&[u8], String, ()> {
map_res(take_until(" "), |s| from_utf8(s).map(|s| s.to_string()))(i)
map_res(take_until(" "), |s| from_utf8(s).map(|s| s.to_string())).parse(i)
}

fn space(i: &[u8]) -> IResult<&[u8], (), ()> {
Expand Down
7 changes: 4 additions & 3 deletions examples/sync_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use nom::{
bytes::streaming::{tag, take_until},
character::streaming::space0,
combinator::map_res,
IResult,
IResult, Parser,
};
use nom_bufreader::bufreader::BufReader;
use nom_bufreader::{Error, Parse};
Expand All @@ -12,11 +12,12 @@ use std::{net::TcpListener, str::from_utf8};
fn method(i: &[u8]) -> IResult<&[u8], String, ()> {
map_res(alt((tag("GET"), tag("POST"), tag("HEAD"))), |s| {
from_utf8(s).map(|s| s.to_string())
})(i)
})
.parse(i)
}

fn path(i: &[u8]) -> IResult<&[u8], String, ()> {
map_res(take_until(" "), |s| from_utf8(s).map(|s| s.to_string()))(i)
map_res(take_until(" "), |s| from_utf8(s).map(|s| s.to_string())).parse(i)
}

fn space(i: &[u8]) -> IResult<&[u8], (), ()> {
Expand Down
7 changes: 4 additions & 3 deletions examples/tokio_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use nom::{
bytes::streaming::{tag, take_until},
character::streaming::space0,
combinator::map_res,
IResult,
IResult, Parser,
};
use nom_bufreader::async_bufreader::BufReader;
use nom_bufreader::{AsyncParse, Error};
Expand All @@ -13,11 +13,12 @@ use tokio_util::compat::TokioAsyncReadCompatExt;
fn method(i: &[u8]) -> IResult<&[u8], String, ()> {
map_res(alt((tag("GET"), tag("POST"), tag("HEAD"))), |s| {
from_utf8(s).map(|s| s.to_string())
})(i)
})
.parse(i)
}

fn path(i: &[u8]) -> IResult<&[u8], String, ()> {
map_res(take_until(" "), |s| from_utf8(s).map(|s| s.to_string()))(i)
map_res(take_until(" "), |s| from_utf8(s).map(|s| s.to_string())).parse(i)
}

fn space(i: &[u8]) -> IResult<&[u8], (), ()> {
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ impl<E> From<io::Error> for Error<E> {
pub trait Parse<O, E, P> {
fn parse(&mut self, p: P) -> Result<O, Error<E>>
where
for<'a> P: Parser<&'a [u8], O, E>;
for<'a> P: Parser<&'a [u8], Output = O, Error = E>;
}

impl<R: Read, O, E, P> Parse<O, E, P> for std::io::BufReader<R> {
fn parse(&mut self, mut p: P) -> Result<O, Error<E>>
where
for<'a> P: Parser<&'a [u8], O, E>,
for<'a> P: Parser<&'a [u8], Output = O, Error = E>,
{
loop {
let opt =
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<R: Read, O, E, P> Parse<O, E, P> for std::io::BufReader<R> {
impl<R: Read, O, E, P> Parse<O, E, P> for bufreader::BufReader<R> {
fn parse(&mut self, mut p: P) -> Result<O, Error<E>>
where
for<'a> P: Parser<&'a [u8], O, E>,
for<'a> P: Parser<&'a [u8], Output = O, Error = E>,
{
let mut eof = false;
let mut error = None;
Expand Down Expand Up @@ -195,15 +195,15 @@ impl<R: Read, O, E, P> Parse<O, E, P> for bufreader::BufReader<R> {
pub trait AsyncParse<O, E, P> {
async fn parse(&mut self, p: P) -> Result<O, Error<E>>
where
for<'a> P: Parser<&'a [u8], O, E> + Send + 'async_trait;
for<'a> P: Parser<&'a [u8], Output = O, Error = E> + Send + 'async_trait;
}

#[cfg(feature = "async")]
#[async_trait]
impl<R: AsyncRead + Unpin + Send, O: Send, E, P> AsyncParse<O, E, P> for BufReader<R> {
async fn parse(&mut self, mut p: P) -> Result<O, Error<E>>
where
for<'a> P: Parser<&'a [u8], O, E> + Send + 'async_trait,
for<'a> P: Parser<&'a [u8], Output = O, Error = E> + Send + 'async_trait,
{
loop {
let opt =
Expand Down Expand Up @@ -240,7 +240,7 @@ impl<R: AsyncRead + Unpin + Send, O: Send, E, P> AsyncParse<O, E, P>
{
async fn parse(&mut self, mut p: P) -> Result<O, Error<E>>
where
for<'a> P: Parser<&'a [u8], O, E> + Send + 'async_trait,
for<'a> P: Parser<&'a [u8], Output = O, Error = E> + Send + 'async_trait,
{
loop {
let opt =
Expand Down