Macro combine::decode_futures_03 [−][src]
macro_rules! decode_futures_03 {
($decoder : expr, $read : expr, $parser : expr) => { ... };
($decoder : expr, $read : expr, $parser : expr, $input_stream : expr $(,) ?) => { ... };
($decoder : expr, $read : expr, $parser : expr, $input_stream : expr,
$post_decode : expr $(,) ?) => { ... };
}
This is supported on crate feature
futures-io-03
only.Expand description
Parses an instance of futures::io::AsyncRead
as a &[u8]
without reading the entire file into
memory.
This is defined as a macro to work around the lack of Higher Ranked Types. See the
example for how to pass a parser to the macro (constructing parts of the parser outside of
the decode!
call is unlikely to work.
use futures::pin_mut;
use async_std::{
fs::File,
task,
};
use combine::{decode_futures_03, satisfy, skip_many1, many1, sep_end_by, Parser, stream::Decoder};
fn main() {
task::block_on(main_());
}
async fn main_() {
let mut read = File::open("README.md").await.unwrap();
let mut decoder = Decoder::new();
let is_whitespace = |b: u8| b == b' ' || b == b'\r' || b == b'\n';
assert_eq!(
decode_futures_03!(
decoder,
read,
{
let word = many1(satisfy(|b| !is_whitespace(b)));
sep_end_by(word, skip_many1(satisfy(is_whitespace))).map(|words: Vec<Vec<u8>>| words.len())
},
|input, _position| combine::easy::Stream::from(input),
).map_err(combine::easy::Errors::<u8, &[u8], _>::from),
Ok(819),
);
}