| use crate::lib::future::Future; | ||
| use crate::lib::marker::Unpin; | ||
| use crate::lib::pin::Pin; | ||
| use crate::lib::task::{Context, Poll}; | ||
| // Replace usage of this with std::future::poll_fn once it stabilizes | ||
| pub struct PollFn<F> { | ||
| f: F, | ||
| } | ||
| impl<F> Unpin for PollFn<F> {} | ||
| pub fn poll_fn<T, F>(f: F) -> PollFn<F> | ||
| where | ||
| F: FnMut(&mut Context<'_>) -> Poll<T>, | ||
| { | ||
| PollFn { f } | ||
| } | ||
| impl<T, F> Future for PollFn<F> | ||
| where | ||
| F: FnMut(&mut Context<'_>) -> Poll<T>, | ||
| { | ||
| type Output = T; | ||
| fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { | ||
| (&mut self.f)(cx) | ||
| } | ||
| } |
| { | ||
| "git": { | ||
| "sha1": "a5199c9ff48a45a773befbfb2296f3ecabfa6ed1" | ||
| "sha1": "cd35e54a4e9c555da87984fa665542e31f04e306" | ||
| } | ||
| } |
+11
-9
@@ -0,1 +1,3 @@ | ||
| #![cfg(feature = "std")] | ||
| #[macro_use] | ||
@@ -32,3 +34,4 @@ extern crate criterion; | ||
| fn is_token(c: u8) -> bool { | ||
| match c { | ||
| !matches!( | ||
| c, | ||
| 128..=255 | ||
@@ -53,5 +56,4 @@ | 0..=31 | ||
| | b'}' | ||
| | b' ' => false, | ||
| _ => true, | ||
| } | ||
| | b' ' | ||
| ) | ||
| } | ||
@@ -69,3 +71,3 @@ | ||
| fn is_http_version(c: u8) -> bool { | ||
| c >= b'0' && c <= b'9' || c == b'.' | ||
| (b'0'..=b'9').contains(&c) || c == b'.' | ||
| } | ||
@@ -100,5 +102,5 @@ | ||
| fn parse_http_request<'a, Input>( | ||
| input: Input, | ||
| ) -> Result<((Request<'a>, Vec<Header<'a>>), Input), Input::Error> | ||
| type HttpRequest<'a> = (Request<'a>, Vec<Header<'a>>); | ||
| fn parse_http_request<'a, Input>(input: Input) -> Result<(HttpRequest<'a>, Input), Input::Error> | ||
| where | ||
@@ -129,3 +131,3 @@ Input: RangeStream<Token = u8, Range = &'a [u8]>, | ||
| static REQUESTS: &'static [u8] = include_bytes!("http-requests.txt"); | ||
| static REQUESTS: &[u8] = include_bytes!("http-requests.txt"); | ||
@@ -132,0 +134,0 @@ fn http_requests_small(b: &mut Bencher<'_>) { |
+11
-9
| // `impl Trait` is not required for this parser but we use to to show that it can be used to | ||
| // significantly simplify things | ||
| #![cfg(feature = "std")] | ||
| #[macro_use] | ||
@@ -226,3 +228,3 @@ extern crate criterion; | ||
| println!("{}", e); | ||
| assert!(false); | ||
| panic!(); | ||
| } | ||
@@ -245,6 +247,6 @@ } | ||
| Ok((Value::Array(_), _)) => (), | ||
| Ok(_) => assert!(false), | ||
| Ok(_) => panic!(), | ||
| Err(err) => { | ||
| println!("{}", err); | ||
| assert!(false); | ||
| panic!(); | ||
| } | ||
@@ -263,6 +265,6 @@ } | ||
| Ok((Value::Array(_), _)) => (), | ||
| Ok(_) => assert!(false), | ||
| Ok(_) => panic!(), | ||
| Err(err) => { | ||
| println!("{}", err); | ||
| assert!(false); | ||
| panic!(); | ||
| } | ||
@@ -281,6 +283,6 @@ } | ||
| Ok((Value::Array(_), _)) => (), | ||
| Ok(_) => assert!(false), | ||
| Ok(_) => panic!(), | ||
| Err(err) => { | ||
| println!("{}", err); | ||
| assert!(false); | ||
| panic!(); | ||
| } | ||
@@ -307,6 +309,6 @@ } | ||
| } | ||
| Ok(_) => assert!(false), | ||
| Ok(_) => panic!(), | ||
| Err(err) => { | ||
| println!("{}", err); | ||
| assert!(false); | ||
| panic!(); | ||
| } | ||
@@ -313,0 +315,0 @@ } |
+4
-2
| # This file is automatically @generated by Cargo. | ||
| # It is not intended for manual editing. | ||
| version = 3 | ||
| [[package]] | ||
@@ -269,3 +271,3 @@ name = "aho-corasick" | ||
| name = "combine" | ||
| version = "4.6.0" | ||
| version = "4.6.1" | ||
| dependencies = [ | ||
@@ -277,4 +279,4 @@ "async-std", | ||
| "futures 0.3.8", | ||
| "futures-core", | ||
| "futures-io", | ||
| "futures-util", | ||
| "memchr", | ||
@@ -281,0 +283,0 @@ "once_cell", |
+21
-17
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "combine" | ||
| version = "4.6.0" | ||
| version = "4.6.1" | ||
| authors = ["Markus Westerlind <marwes91@gmail.com>"] | ||
@@ -39,3 +39,3 @@ description = "Fast parser combinators on arbitrary streams with zero-copy support." | ||
| name = "async" | ||
| required-features = ["std"] | ||
| required-features = ["std", "tokio"] | ||
@@ -56,3 +56,3 @@ [[example]] | ||
| name = "async" | ||
| required-features = ["tokio-02", "futures-util-03"] | ||
| required-features = ["tokio-02", "futures-io-03"] | ||
@@ -62,2 +62,3 @@ [[bench]] | ||
| harness = false | ||
| required-features = ["std"] | ||
@@ -67,2 +68,3 @@ [[bench]] | ||
| harness = false | ||
| required-features = ["std"] | ||
@@ -82,14 +84,13 @@ [[bench]] | ||
| [dependencies.futures-io-03] | ||
| [dependencies.futures-core-03] | ||
| version = "0.3.1" | ||
| optional = true | ||
| default-features = false | ||
| package = "futures-io" | ||
| package = "futures-core" | ||
| [dependencies.futures-util-03] | ||
| [dependencies.futures-io-03] | ||
| version = "0.3.1" | ||
| features = ["io", "std"] | ||
| optional = true | ||
| default-features = false | ||
| package = "futures-util" | ||
| package = "futures-io" | ||
@@ -126,2 +127,8 @@ [dependencies.memchr] | ||
| package = "tokio" | ||
| [dependencies.tokio-util] | ||
| version = "0.6" | ||
| features = ["codec"] | ||
| optional = true | ||
| default-features = false | ||
| [dev-dependencies.async-std] | ||
@@ -173,14 +180,11 @@ version = "1" | ||
| [dev-dependencies.tokio-util] | ||
| version = "0.6" | ||
| features = ["codec"] | ||
| [features] | ||
| alloc = [] | ||
| default = ["std"] | ||
| futures-03 = ["pin-project", "std", "futures-io-03", "futures-util-03", "pin-project-lite"] | ||
| futures-03 = ["pin-project", "std", "futures-core-03", "futures-io-03", "pin-project-lite"] | ||
| mp4 = [] | ||
| pin-project = ["pin-project-lite"] | ||
| std = ["memchr/use_std", "bytes"] | ||
| tokio = ["tokio-dep", "futures-util-03", "pin-project-lite"] | ||
| tokio-02 = ["pin-project", "std", "tokio-02-dep", "futures-util-03", "pin-project-lite", "bytes_05"] | ||
| tokio-03 = ["pin-project", "std", "tokio-03-dep", "futures-util-03", "pin-project-lite"] | ||
| std = ["memchr/use_std", "bytes", "alloc"] | ||
| tokio = ["tokio-dep", "tokio-util/io", "futures-core-03", "pin-project-lite"] | ||
| tokio-02 = ["pin-project", "std", "tokio-02-dep", "futures-core-03", "pin-project-lite", "bytes_05"] | ||
| tokio-03 = ["pin-project", "std", "tokio-03-dep", "futures-core-03", "pin-project-lite"] |
+11
-0
@@ -0,1 +1,12 @@ | ||
| <a name="v4.6.1"></a> | ||
| ### v4.6.1 (2021-08-25) | ||
| #### Performance | ||
| * Avoid a saturating add in slice_uncons_while ([7f330b0c](https://github.com/Marwes/combine/commit/7f330b0cacd61131df88c919074ffa8136100299)) | ||
| * Avoid a saturating add in slice_uncons_while ([ad4180dd](https://github.com/Marwes/combine/commit/ad4180dd7d3530d47502795ead21e13b7816aed7)) | ||
| <a name="v4.6.0"></a> | ||
@@ -2,0 +13,0 @@ ## v4.6.0 (2021-06-16) |
| #![cfg(feature = "std")] | ||
| #![cfg(feature = "tokio")] | ||
@@ -3,0 +4,0 @@ use std::{cell::Cell, io::Cursor, rc::Rc, str}; |
+3
-2
@@ -46,2 +46,4 @@ use crate::lib::fmt; | ||
| type Format: fmt::Display; | ||
| #[allow(clippy::wrong_self_convention)] | ||
| fn into_info(&'s self) -> Info<T, R, Self::Format>; | ||
@@ -1091,4 +1093,3 @@ } | ||
| ][..]; | ||
| let result = | ||
| crate::parser::range::take_while(|c: CloneOnly| c.s == "x".to_string()).parse(input); | ||
| let result = crate::parser::range::take_while(|c: CloneOnly| c.s == "x").parse(input); | ||
| assert_eq!( | ||
@@ -1095,0 +1096,0 @@ result, |
+9
-3
@@ -198,2 +198,5 @@ //! This crate contains parser combinators, roughly based on the Haskell libraries | ||
| #[cfg(feature = "alloc")] | ||
| extern crate alloc; | ||
| #[doc(inline)] | ||
@@ -620,2 +623,5 @@ pub use crate::error::{ParseError, ParseResult, StdParseResult}; | ||
| #[cfg(feature = "futures-core-03")] | ||
| pub mod future_ext; | ||
| #[doc(hidden)] | ||
@@ -705,3 +711,3 @@ #[derive(Clone, PartialOrd, PartialEq, Debug, Copy)] | ||
| fn integer<'a, Input>(input: &mut Input) -> StdParseResult<i64, Input> | ||
| fn integer<Input>(input: &mut Input) -> StdParseResult<i64, Input> | ||
| where | ||
@@ -870,7 +876,7 @@ Input: Stream<Token = char>, | ||
| match p.easy_parse(position::Stream::new("le123")) { | ||
| Ok(_) => assert!(false), | ||
| Ok(_) => panic!(), | ||
| Err(err) => assert_eq!(err.position, SourcePosition { line: 1, column: 1 }), | ||
| } | ||
| match p.easy_parse(position::Stream::new("let1")) { | ||
| Ok(_) => assert!(false), | ||
| Ok(_) => panic!(), | ||
| Err(err) => assert_eq!(err.position, SourcePosition { line: 1, column: 4 }), | ||
@@ -877,0 +883,0 @@ } |
@@ -223,3 +223,3 @@ //! Module containing parsers specialized on byte streams. | ||
| { | ||
| satisfy(|ch| ch >= b'0' && ch <= b'7').expected("octal digit") | ||
| satisfy(|ch| (b'0'..=b'7').contains(&ch)).expected("octal digit") | ||
| } | ||
@@ -603,3 +603,3 @@ | ||
| #[cfg(test)] | ||
| #[cfg(all(feature = "std", test))] | ||
| mod tests { | ||
@@ -646,3 +646,3 @@ | ||
| #[cfg(test)] | ||
| #[cfg(all(feature = "std", test))] | ||
| mod tests { | ||
@@ -649,0 +649,0 @@ |
@@ -838,3 +838,3 @@ //! Combinators which take one or more parsers and attempts to parse successfully with at least one | ||
| #[cfg(test)] | ||
| #[cfg(all(feature = "std", test))] | ||
| mod tests { | ||
@@ -841,0 +841,0 @@ |
+37
-31
@@ -15,2 +15,8 @@ //! Various combinators which do not fit anywhere else. | ||
| #[cfg(feature = "alloc")] | ||
| use alloc::{boxed::Box, string::String, vec::Vec}; | ||
| #[cfg(feature = "alloc")] | ||
| use crate::lib::any::Any; | ||
| #[derive(Copy, Clone)] | ||
@@ -715,12 +721,12 @@ pub struct NotFollowedBy<P>(P); | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
| #[derive(Default)] | ||
| pub struct AnyPartialState(Option<Box<dyn std::any::Any>>); | ||
| pub struct AnyPartialState(Option<Box<dyn Any>>); | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
| pub struct AnyPartialStateParser<P>(P); | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| impl<Input, P> Parser<Input> for AnyPartialStateParser<P> | ||
@@ -808,3 +814,3 @@ where | ||
| /// ``` | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
@@ -820,12 +826,12 @@ pub fn any_partial_state<Input, P>(p: P) -> AnyPartialStateParser<P> | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
| #[derive(Default)] | ||
| pub struct AnySendPartialState(Option<Box<dyn std::any::Any + Send>>); | ||
| pub struct AnySendPartialState(Option<Box<dyn Any + Send>>); | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
| pub struct AnySendPartialStateParser<P>(P); | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| impl<Input, P> Parser<Input> for AnySendPartialStateParser<P> | ||
@@ -913,3 +919,3 @@ where | ||
| /// ``` | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
@@ -925,12 +931,12 @@ pub fn any_send_partial_state<Input, P>(p: P) -> AnySendPartialStateParser<P> | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
| #[derive(Default)] | ||
| pub struct AnySendSyncPartialState(Option<Box<dyn std::any::Any + Send + Sync>>); | ||
| pub struct AnySendSyncPartialState(Option<Box<dyn Any + Send + Sync>>); | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
| pub struct AnySendSyncPartialStateParser<P>(P); | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| impl<Input, P> Parser<Input> for AnySendSyncPartialStateParser<P> | ||
@@ -1017,3 +1023,3 @@ where | ||
| /// ``` | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
@@ -1189,11 +1195,11 @@ pub fn any_send_sync_partial_state<Input, P>(p: P) -> AnySendSyncPartialStateParser<P> | ||
| pub trait StrLike: Sealed { | ||
| fn from_utf8(&self) -> Result<&str, ()>; | ||
| fn from_utf8(&self) -> Option<&str>; | ||
| } | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| impl Sealed for String {} | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| impl StrLike for String { | ||
| fn from_utf8(&self) -> Result<&str, ()> { | ||
| Ok(self) | ||
| fn from_utf8(&self) -> Option<&str> { | ||
| Some(self) | ||
| } | ||
@@ -1204,4 +1210,4 @@ } | ||
| impl<'a> StrLike for &'a str { | ||
| fn from_utf8(&self) -> Result<&str, ()> { | ||
| Ok(*self) | ||
| fn from_utf8(&self) -> Option<&str> { | ||
| Some(*self) | ||
| } | ||
@@ -1212,12 +1218,12 @@ } | ||
| impl StrLike for str { | ||
| fn from_utf8(&self) -> Result<&str, ()> { | ||
| Ok(self) | ||
| fn from_utf8(&self) -> Option<&str> { | ||
| Some(self) | ||
| } | ||
| } | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| impl Sealed for Vec<u8> {} | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| impl StrLike for Vec<u8> { | ||
| fn from_utf8(&self) -> Result<&str, ()> { | ||
| fn from_utf8(&self) -> Option<&str> { | ||
| (**self).from_utf8() | ||
@@ -1229,3 +1235,3 @@ } | ||
| impl<'a> StrLike for &'a [u8] { | ||
| fn from_utf8(&self) -> Result<&str, ()> { | ||
| fn from_utf8(&self) -> Option<&str> { | ||
| (**self).from_utf8() | ||
@@ -1237,4 +1243,4 @@ } | ||
| impl StrLike for [u8] { | ||
| fn from_utf8(&self) -> Result<&str, ()> { | ||
| str::from_utf8(self).map_err(|_| ()) | ||
| fn from_utf8(&self) -> Option<&str> { | ||
| str::from_utf8(self).ok() | ||
| } | ||
@@ -1290,3 +1296,3 @@ } | ||
| r.from_utf8() | ||
| .map_err(|_| StreamErrorFor::<Input>::expected_static_message("UTF-8")) | ||
| .ok_or_else(|| StreamErrorFor::<Input>::expected_static_message("UTF-8")) | ||
| .and_then(|s| s.parse().map_err(StreamErrorFor::<Input>::message_format)) | ||
@@ -1293,0 +1299,0 @@ }) |
@@ -30,2 +30,5 @@ //! A collection of both concrete parsers as well as parser combinators. | ||
| #[cfg(feature = "alloc")] | ||
| use alloc::boxed::Box; | ||
| /// Internal API. May break without a semver bump | ||
@@ -850,3 +853,3 @@ #[macro_export] | ||
| /// ``` | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
@@ -1091,3 +1094,3 @@ fn boxed<'a>( | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| impl<P, Input> Parser<Input> for Box<P> | ||
@@ -1094,0 +1097,0 @@ where |
@@ -182,2 +182,3 @@ //! Combinators which take multiple parsers and applies them one after another. | ||
| state.offset = $h.parser_count().0.saturating_add(1); | ||
| // SAFETY: must be set to avoid UB below when unwrapping | ||
| state.$h.value = Some(temp); | ||
@@ -215,2 +216,3 @@ | ||
| state.offset = state.offset.saturating_add($id.parser_count().0); | ||
| // SAFETY: must be set to avoid UB below when unwrapping | ||
| state.$id.value = Some(temp); | ||
@@ -224,2 +226,3 @@ | ||
| // SAFETY: requires both $h and $id to be set, see previous SAFETY comments | ||
| let value = unsafe { (state.$h.unwrap_value(), $(state.$id.unwrap_value()),*) }; | ||
@@ -791,3 +794,3 @@ if first_empty_parser != 0 { | ||
| #[cfg(test)] | ||
| #[cfg(all(feature = "std", test))] | ||
| mod tests { | ||
@@ -794,0 +797,0 @@ |
+66
-89
@@ -11,3 +11,3 @@ use std::io::{self, BufRead, Read}; | ||
| #[cfg(feature = "futures-util-03")] | ||
| #[cfg(feature = "futures-core-03")] | ||
| use std::task::{Context, Poll}; | ||
@@ -29,4 +29,4 @@ | ||
| #[cfg(feature = "futures-util-03")] | ||
| use futures_util_03::ready; | ||
| #[cfg(feature = "futures-core-03")] | ||
| use futures_core_03::ready; | ||
@@ -213,3 +213,3 @@ #[cfg(feature = "pin-project-lite")] | ||
| where | ||
| R: futures_util_03::io::AsyncRead, | ||
| R: futures_io_03::AsyncRead, | ||
| { | ||
@@ -256,2 +256,13 @@ fn poll_extend_buf( | ||
| #[cfg(feature = "tokio-03")] | ||
| fn tokio_03_to_read_buf(bs: &mut BytesMut) -> tokio_03_dep::io::ReadBuf<'_> { | ||
| let uninit = bs.chunk_mut(); | ||
| unsafe { | ||
| tokio_03_dep::io::ReadBuf::uninit(std::slice::from_raw_parts_mut( | ||
| uninit.as_mut_ptr() as *mut MaybeUninit<u8>, | ||
| uninit.len(), | ||
| )) | ||
| } | ||
| } | ||
| #[cfg(feature = "tokio-03")] | ||
| impl<R> CombineRead<R, dyn tokio_03_dep::io::AsyncRead> for Buffer | ||
@@ -266,18 +277,3 @@ where | ||
| ) -> Poll<io::Result<usize>> { | ||
| if !self.0.has_remaining_mut() { | ||
| self.0.reserve(8 * 1024); | ||
| } | ||
| let uninit = self.0.chunk_mut(); | ||
| let mut buf = unsafe { | ||
| tokio_03_dep::io::ReadBuf::uninit(std::slice::from_raw_parts_mut( | ||
| uninit.as_mut_ptr() as *mut MaybeUninit<u8>, | ||
| uninit.len(), | ||
| )) | ||
| }; | ||
| ready!(read.poll_read(cx, &mut buf))?; | ||
| let n = buf.filled().len(); | ||
| unsafe { | ||
| self.0.advance_mut(n); | ||
| } | ||
| Poll::Ready(Ok(n)) | ||
| tokio_03_read_buf(cx, read, &mut self.0) | ||
| } | ||
@@ -296,9 +292,5 @@ } | ||
| let mut buf = tokio_03_to_read_buf(bs); | ||
| ready!(read.poll_read(cx, &mut buf))?; | ||
| unsafe { | ||
| let uninit = bs.chunk_mut(); | ||
| let mut buf = tokio_03_dep::io::ReadBuf::uninit(std::slice::from_raw_parts_mut( | ||
| uninit.as_mut_ptr() as *mut MaybeUninit<u8>, | ||
| uninit.len(), | ||
| )); | ||
| ready!(read.poll_read(cx, &mut buf))?; | ||
| let n = buf.filled().len(); | ||
@@ -320,16 +312,3 @@ bs.advance_mut(n); | ||
| ) -> Poll<io::Result<usize>> { | ||
| if !self.0.has_remaining_mut() { | ||
| self.0.reserve(8 * 1024); | ||
| } | ||
| let mut buf = unsafe { | ||
| tokio_dep::io::ReadBuf::uninit( | ||
| &mut *(self.0.chunk_mut() as *mut _ as *mut [MaybeUninit<u8>]), | ||
| ) | ||
| }; | ||
| ready!(read.poll_read(cx, &mut buf))?; | ||
| let n = buf.filled().len(); | ||
| unsafe { | ||
| self.0.advance_mut(n); | ||
| } | ||
| Poll::Ready(Ok(n)) | ||
| tokio_read_buf(read, cx, &mut self.0) | ||
| } | ||
@@ -340,4 +319,4 @@ } | ||
| fn tokio_read_buf( | ||
| read: Pin<&mut impl tokio_dep::io::AsyncRead>, | ||
| cx: &mut Context<'_>, | ||
| read: Pin<&mut impl tokio_dep::io::AsyncRead>, | ||
| bs: &mut bytes::BytesMut, | ||
@@ -349,13 +328,3 @@ ) -> Poll<io::Result<usize>> { | ||
| unsafe { | ||
| let uninit = bs.chunk_mut(); | ||
| let mut buf = tokio_dep::io::ReadBuf::uninit(std::slice::from_raw_parts_mut( | ||
| uninit.as_mut_ptr() as *mut MaybeUninit<u8>, | ||
| uninit.len(), | ||
| )); | ||
| ready!(read.poll_read(cx, &mut buf))?; | ||
| let n = buf.filled().len(); | ||
| bs.advance_mut(n); | ||
| Poll::Ready(Ok(n)) | ||
| } | ||
| tokio_util::io::poll_read_buf(read, cx, bs) | ||
| } | ||
@@ -401,23 +370,26 @@ | ||
| // Copy of tokio's read_buf method (but it has to force initialize the buffer) | ||
| let copied = unsafe { | ||
| let n = { | ||
| let bs = buf.chunk_mut(); | ||
| // Copy of tokio's poll_read_buf method (but it has to force initialize the buffer) | ||
| let n = { | ||
| let bs = buf.chunk_mut(); | ||
| for i in 0..bs.len() { | ||
| bs.write_byte(i, 0); | ||
| } | ||
| for i in 0..bs.len() { | ||
| bs.write_byte(i, 0); | ||
| } | ||
| // Convert to `&mut [u8]` | ||
| let bs = &mut *(bs as *mut _ as *mut [u8]); | ||
| // Convert to `&mut [u8]` | ||
| // SAFETY: the entire buffer is preinitialized above | ||
| let bs = unsafe { &mut *(bs as *mut _ as *mut [u8]) }; | ||
| let n = read.read(bs)?; | ||
| assert!(n <= bs.len(), "AsyncRead reported that it initialized more than the number of bytes in the buffer"); | ||
| n | ||
| }; | ||
| buf.advance_mut(n); | ||
| let n = read.read(bs)?; | ||
| assert!( | ||
| n <= bs.len(), | ||
| "AsyncRead reported that it initialized more than the number of bytes in the buffer" | ||
| ); | ||
| n | ||
| }; | ||
| Ok(copied) | ||
| // SAFETY: the entire buffer has been preinitialized | ||
| unsafe { buf.advance_mut(n) }; | ||
| Ok(n) | ||
| } | ||
@@ -488,3 +460,3 @@ | ||
| tokio_read_buf(cx, me.inner, me.buf) | ||
| tokio_read_buf(me.inner, cx, me.buf) | ||
| } | ||
@@ -496,3 +468,3 @@ } | ||
| where | ||
| R: futures_util_03::io::AsyncRead, | ||
| R: futures_io_03::AsyncRead, | ||
| { | ||
@@ -535,20 +507,26 @@ fn poll_extend_buf( | ||
| where | ||
| R: futures_util_03::io::AsyncRead, | ||
| R: futures_io_03::AsyncRead, | ||
| { | ||
| // Copy of tokio's read_buf method (but it has to force initialize the buffer) | ||
| let copied = unsafe { | ||
| let n = { | ||
| let bs = buf.chunk_mut(); | ||
| // Convert to `&mut [u8]` | ||
| let bs = &mut *(bs as *mut _ as *mut [u8]); | ||
| let n = { | ||
| let bs = buf.chunk_mut(); | ||
| // preinit the buffer | ||
| for i in 0..bs.len() { | ||
| bs.write_byte(i, 0); | ||
| } | ||
| let n = ready!(read.poll_read(cx, bs))?; | ||
| assert!(n <= bs.len(), "AsyncRead reported that it initialized more than the number of bytes in the buffer"); | ||
| n | ||
| }; | ||
| // Convert to `&mut [u8]` | ||
| // SAFETY: preinitialize the buffer | ||
| let bs = unsafe { &mut *(bs as *mut _ as *mut [u8]) }; | ||
| buf.advance_mut(n); | ||
| let n = ready!(read.poll_read(cx, bs))?; | ||
| assert!( | ||
| n <= bs.len(), | ||
| "AsyncRead reported that it initialized more than the number of bytes in the buffer" | ||
| ); | ||
| n | ||
| }; | ||
| Poll::Ready(Ok(copied)) | ||
| // SAFETY: the buffer was preinitialized | ||
| unsafe { buf.advance_mut(n) }; | ||
| Poll::Ready(Ok(n)) | ||
| } | ||
@@ -730,3 +708,3 @@ | ||
| if me.buf.is_empty() { | ||
| ready!(tokio_read_buf(cx, me.inner, me.buf))?; | ||
| ready!(tokio_read_buf(me.inner, cx, me.buf))?; | ||
| } | ||
@@ -817,4 +795,3 @@ Poll::Ready(Ok(&me.buf[..])) | ||
| async fn extend_buf_tokio_02(mut self: Pin<&mut Self>) -> io::Result<usize> { | ||
| futures_util_03::future::poll_fn(|cx| Bufferless.poll_extend_buf(cx, self.as_mut())) | ||
| .await | ||
| crate::future_ext::poll_fn(|cx| Bufferless.poll_extend_buf(cx, self.as_mut())).await | ||
| } | ||
@@ -859,3 +836,3 @@ } | ||
| let read = BufReader::with_capacity(3, &[1u8, 2, 3, 4, 5, 6, 7, 8, 9, 0][..]); | ||
| futures_util_03::pin_mut!(read); | ||
| futures_03_dep::pin_mut!(read); | ||
@@ -887,4 +864,3 @@ assert_eq!(read.as_mut().extend_buf_tokio_02().await.unwrap(), 3); | ||
| async fn extend_buf_tokio(mut self: Pin<&mut Self>) -> io::Result<usize> { | ||
| futures_util_03::future::poll_fn(|cx| Bufferless.poll_extend_buf(cx, self.as_mut())) | ||
| .await | ||
| crate::future_ext::poll_fn(|cx| Bufferless.poll_extend_buf(cx, self.as_mut())).await | ||
| } | ||
@@ -929,3 +905,3 @@ } | ||
| let read = BufReader::with_capacity(3, &[1u8, 2, 3, 4, 5, 6, 7, 8, 9, 0][..]); | ||
| futures_util_03::pin_mut!(read); | ||
| futures_03_dep::pin_mut!(read); | ||
@@ -947,2 +923,3 @@ assert_eq!(read.as_mut().extend_buf_tokio().await.unwrap(), 3); | ||
| #[test] | ||
| #[allow(clippy::unused_io_amount)] | ||
| fn buf_reader() { | ||
@@ -949,0 +926,0 @@ let mut read = BufReader::with_capacity(3, &[1u8, 2, 3, 4, 5, 6, 7, 8, 9, 0][..]); |
@@ -1,2 +0,2 @@ | ||
| use std::collections::VecDeque; | ||
| use alloc::collections::VecDeque; | ||
@@ -3,0 +3,0 @@ use crate::{ |
@@ -164,3 +164,3 @@ use crate::{ | ||
| let copied = | ||
| futures_util_03::future::poll_fn(|cx| self.buffer.poll_extend_buf(cx, reader.as_mut())) | ||
| crate::future_ext::poll_fn(|cx| self.buffer.poll_extend_buf(cx, reader.as_mut())) | ||
| .await?; | ||
@@ -184,3 +184,3 @@ if copied == 0 { | ||
| let copied = | ||
| futures_util_03::future::poll_fn(|cx| self.buffer.poll_extend_buf(cx, reader.as_mut())) | ||
| crate::future_ext::poll_fn(|cx| self.buffer.poll_extend_buf(cx, reader.as_mut())) | ||
| .await?; | ||
@@ -204,3 +204,3 @@ if copied == 0 { | ||
| let copied = | ||
| futures_util_03::future::poll_fn(|cx| self.buffer.poll_extend_buf(cx, reader.as_mut())) | ||
| crate::future_ext::poll_fn(|cx| self.buffer.poll_extend_buf(cx, reader.as_mut())) | ||
| .await?; | ||
@@ -207,0 +207,0 @@ if copied == 0 { |
+23
-9
@@ -55,3 +55,3 @@ // | ||
| /// one. | ||
| #[cfg(feature = "std")] | ||
| #[cfg(feature = "alloc")] | ||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
@@ -580,3 +580,3 @@ pub mod buffered; | ||
| None => false, | ||
| Some(&b) => b < 128 || b >= 192, | ||
| Some(b) => !(128..=192).contains(b), | ||
| } | ||
@@ -621,3 +621,9 @@ } | ||
| fn slice_uncons_while<'a, T, F>(slice: &mut &'a [T], mut i: usize, mut f: F) -> &'a [T] | ||
| #[repr(usize)] | ||
| enum UnconsStart { | ||
| Zero = 0, | ||
| One = 1, | ||
| } | ||
| fn slice_uncons_while<'a, T, F>(slice: &mut &'a [T], start: UnconsStart, mut f: F) -> &'a [T] | ||
| where | ||
@@ -627,3 +633,6 @@ F: FnMut(T) -> bool, | ||
| { | ||
| let mut i = start as usize; | ||
| let len = slice.len(); | ||
| // SAFETY: We only call this function with `One` if the slice has length >= 1 | ||
| debug_assert!(len >= i, ""); | ||
| let mut found = false; | ||
@@ -641,2 +650,3 @@ | ||
| // SAFETY: ensures we can access at least 8 elements starting at i, making get_unchecked sound. | ||
| while len - i >= 8 { | ||
@@ -687,3 +697,3 @@ check!(); | ||
| { | ||
| Ok(slice_uncons_while(self, 0, f)) | ||
| Ok(slice_uncons_while(self, UnconsStart::Zero, f)) | ||
| } | ||
@@ -707,3 +717,3 @@ | ||
| CommitOk(slice_uncons_while(self, 1, f)) | ||
| CommitOk(slice_uncons_while(self, UnconsStart::One, f)) | ||
| } | ||
@@ -1070,7 +1080,10 @@ | ||
| fn slice_uncons_while_ref<'a, T, F>(slice: &mut &'a [T], mut i: usize, mut f: F) -> &'a [T] | ||
| fn slice_uncons_while_ref<'a, T, F>(slice: &mut &'a [T], start: UnconsStart, mut f: F) -> &'a [T] | ||
| where | ||
| F: FnMut(&'a T) -> bool, | ||
| { | ||
| let mut i = start as usize; | ||
| let len = slice.len(); | ||
| // SAFETY: We only call this function with `One` if the slice has length >= 1 | ||
| debug_assert!(len >= i, ""); | ||
| let mut found = false; | ||
@@ -1088,2 +1101,3 @@ | ||
| // SAFETY: ensures we can access at least 8 elements starting at i, making get_unchecked sound. | ||
| while len - i >= 8 { | ||
@@ -1134,3 +1148,3 @@ check!(); | ||
| { | ||
| Ok(slice_uncons_while_ref(&mut self.0, 0, f)) | ||
| Ok(slice_uncons_while_ref(&mut self.0, UnconsStart::Zero, f)) | ||
| } | ||
@@ -1152,3 +1166,3 @@ | ||
| CommitOk(slice_uncons_while_ref(&mut self.0, 1, f)) | ||
| CommitOk(slice_uncons_while_ref(&mut self.0, UnconsStart::One, f)) | ||
| } | ||
@@ -1891,5 +1905,5 @@ | ||
| input.reset(before.clone()).unwrap(); | ||
| input.reset(before).unwrap(); | ||
| assert_eq!(input.distance(&before), 0); | ||
| } | ||
| } |
@@ -0,1 +1,3 @@ | ||
| #![allow(clippy::single_match)] | ||
| #[macro_use] | ||
@@ -2,0 +4,0 @@ extern crate combine; |
+26
-23
| use combine::{ | ||
| parser::{ | ||
| byte::bytes_cmp, | ||
| char::{digit, letter, string, string_cmp}, | ||
| choice::{choice, optional}, | ||
| combinator::{attempt, no_partial, not_followed_by}, | ||
| error::unexpected, | ||
| range::{self, range}, | ||
| repeat::{count, count_min_max, many, sep_by, sep_end_by1, skip_until, take_until}, | ||
| token::{any, eof, position, token, value, Token}, | ||
| char::{digit, letter}, | ||
| choice::choice, | ||
| combinator::not_followed_by, | ||
| range::range, | ||
| token::{any, eof, token, Token}, | ||
| }, | ||
| EasyParser, Parser, | ||
| Parser, | ||
| }; | ||
@@ -48,17 +45,21 @@ | ||
| mod tests_std { | ||
| use super::*; | ||
| use combine::easy::{Error, Errors}; | ||
| use combine::parser::byte::alpha_num; | ||
| use combine::parser::byte::bytes; | ||
| use combine::parser::byte::bytes_cmp; | ||
| use combine::parser::byte::num::be_u32; | ||
| use combine::parser::char::char; | ||
| use combine::parser::char::{string, string_cmp}; | ||
| use combine::parser::combinator::no_partial; | ||
| use combine::parser::range; | ||
| use combine::parser::repeat::{skip_until, take_until}; | ||
| use combine::stream::position; | ||
| use combine::stream::position::SourcePosition; | ||
| use combine::{ | ||
| parser::{ | ||
| byte::{alpha_num, bytes, num::be_u32}, | ||
| char::{char, digit, letter}, | ||
| }, | ||
| stream::{ | ||
| easy::{self, Error, Errors}, | ||
| position::{self, SourcePosition}, | ||
| }, | ||
| Parser, | ||
| attempt, count, count_min_max, easy, many, optional, position, sep_by, sep_end_by1, | ||
| unexpected, value, EasyParser, | ||
| }; | ||
| use super::*; | ||
| #[derive(Clone, PartialEq, Debug)] | ||
@@ -89,4 +90,6 @@ struct CloneOnly { | ||
| fn sep_by_committed_error() { | ||
| type TwoLettersList = Vec<(char, char)>; | ||
| let mut parser2 = sep_by((letter(), letter()), token(',')); | ||
| let result_err: Result<(Vec<(char, char)>, &str), easy::ParseError<&str>> = | ||
| let result_err: Result<(TwoLettersList, &str), easy::ParseError<&str>> = | ||
| parser2.easy_parse("a,bc"); | ||
@@ -624,3 +627,3 @@ assert!(result_err.is_err()); | ||
| fn lifetime_inference() { | ||
| fn _string<'a>(source: &'a str) { | ||
| fn _string(source: &str) { | ||
| range::take(1).or(string("a")).parse(source).ok(); | ||
@@ -634,3 +637,3 @@ range::take(1) | ||
| } | ||
| fn _bytes<'a>(source: &'a [u8]) { | ||
| fn _bytes(source: &[u8]) { | ||
| range::take(1).or(bytes(&[0u8])).parse(source).ok(); | ||
@@ -637,0 +640,0 @@ range::take(1) |
+3
-0
@@ -14,2 +14,5 @@ #!/bin/bash -x | ||
| cargo "$@" check --bench mp4 --features mp4 | ||
| cargo "$@" build --no-default-features --features alloc | ||
| cargo "$@" test --no-default-features --features alloc --examples | ||
@@ -16,0 +19,0 @@ cargo "$@" build --no-default-features |
Sorry, the diff of this file is not supported yet