macro_rules! decode_tokio {
    ($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 $(,)?) => { ... };
}
Expand description

Parses an instance of tokio::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 tokio::{
    fs::File,
};

use combine::{decode_tokio, satisfy, skip_many1, many1, sep_end_by, Parser, stream::{Decoder, buf_reader::BufReader}};

#[tokio::main]
async fn main() {
    let mut read = BufReader::new(File::open("README.md").await.unwrap());
    let mut decoder = Decoder::new_bufferless();
    let is_whitespace = |b: u8| b == b' ' || b == b'\r' || b == b'\n';
    assert_eq!(
        decode_tokio!(
            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),
    );
}