Function winnow::binary::bits::bool

source ·
pub fn bool<I, E: ParserError<(I, usize)>>(
    input: &mut (I, usize),
) -> PResult<bool, E>
where I: Stream<Token = u8> + AsBytes + StreamIsPartial + Clone,
Expand description

Parses one specific bit as a bool.

§Example

use winnow::binary::bits::bool;

type Stream<'i> = &'i Bytes;

fn stream(b: &[u8]) -> Stream<'_> {
    Bytes::new(b)
}

fn parse(input: (Stream<'_>, usize)) -> IResult<(Stream<'_>, usize), bool> {
    bool.parse_peek(input)
}

assert_eq!(parse((stream(&[0b10000000]), 0)), Ok(((stream(&[0b10000000]), 1), true)));
assert_eq!(parse((stream(&[0b10000000]), 1)), Ok(((stream(&[0b10000000]), 2), false)));