macro_rules! decode {
    ($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 std::io::Read 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 std::{
    fs::File,
};
use combine::{decode, satisfy, skip_many1, many1, sep_end_by, Parser, stream::Decoder};

let mut read = File::open("README.md").unwrap();
let mut decoder = Decoder::new();
let is_whitespace = |b: u8| b == b' ' || b == b'\r' || b == b'\n';
assert_eq!(
    decode!(
        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),
);