Skip to main content

bool

Function bool 

Source
pub fn bool<Input, Error: ParserError<Bits<Input>>>(
    input: &mut Bits<Input>,
) -> Result<bool, Error>
where Input: Stream<Token = u8> + StreamIsPartial + Clone,
Expand description

Parses one specific bit as a bool.

§Effective Signature

Assuming you are parsing a Bits<&[u8]> bit Stream:

pub fn bool(input: &mut Bits<&[u8]>) -> ModalResult<bool>

§Example

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

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

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

fn parse(input: &mut Bits<Stream<'_>>) -> ModalResult<bool> {
    bool.parse_next(input)
}

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