Function nom::bits::bits [−][src]
pub fn bits<I, O, E1: ParseError<(I, usize)> + ErrorConvert<E2>, E2: ParseError<I>, P>(
parser: P
) -> impl Fn(I) -> IResult<I, O, E2> where
I: Slice<RangeFrom<usize>>,
P: Fn((I, usize)) -> IResult<(I, usize), O, E1>,
Converts a byte-level input to a bit-level input, for consumption by a parser that uses bits.
Afterwards, the input is converted back to a byte-level parser, with any remaining bits thrown away.
Example
ⓘ
use nom::bits::bits; use nom::bits::complete::take_bits; fn take_4_bits(input: &[u8]) -> IResult<&[u8], u64> { bits( take_bits(4usize) )(input) } let input = vec![0xAB, 0xCD, 0xEF, 0x12]; let sl = &input[..]; assert_eq!(take_4_bits( sl ), Ok( (&sl[1..], 0xA) ));