/// Parse taking `count` bits and comparing them to `pattern` /// /// # Effective Signature /// /// Assuming you are parsing a `(&[u8], usize)` bit [Stream]: /// ```rust /// # use winnow::prelude::*;; /// # use winnow::error::ContextError; /// pub fn pattern<'i>(pattern: u8, count: usize) -> impl Parser<(&'i [u8], usize), u8, ContextError> /// # { /// # winnow::binary::bits::pattern(pattern, count) /// # } /// ``` /// /// # Example /// /// ```rust /// # use winnow::prelude::*; /// # use winnow::Bytes; /// # use winnow::error::ContextError; /// use winnow::binary::bits::pattern; /// /// type Stream<'i> = &'i Bytes; /// /// fn stream(b: &[u8]) -> Stream<'_> { /// Bytes::new(b) /// } /// /// /// Compare the lowest `count` bits of `input` against the lowest `count` bits of `pattern`. /// /// Return Ok and the matching section of `input` if there's a match. /// /// Return Err if there's no match. /// fn parser(bits: u8, count: u8, input: &mut (Stream<'_>, usize)) -> ModalResult<u8> { /// pattern(bits, count).parse_next(input) /// } /// /// // The lowest 4 bits of 0b00001111 match the lowest 4 bits of 0b11111111. /// assert_eq!( /// pattern::<_, usize, _, ContextError>(0b0000_1111, 4usize).parse_peek((stream(&[0b1111_1111]), 0)), /// Ok(((stream(&[0b1111_1111]), 4), 0b0000_1111)) /// ); /// /// // The lowest bit of 0b00001111 matches the lowest bit of 0b11111111 (both are 1). /// assert_eq!( /// pattern::<_, usize, _, ContextError>(0b00000001, 1usize).parse_peek((stream(&[0b11111111]), 0)), /// Ok(((stream(&[0b11111111]), 1), 0b00000001)) /// ); /// /// // The lowest 2 bits of 0b11111111 and 0b00000001 are different. /// assert!(pattern::<_, usize, _, ContextError>(0b000000_01, 2usize).parse_peek((stream(&[0b111111_11]), 0)).is_err()); /// /// // The lowest 8 bits of 0b11111111 and 0b11111110 are different. /// assert!(pattern::<_, usize, _, ContextError>(0b11111110, 8usize).parse_peek((stream(&[0b11111111]), 0)).is_err()); /// ``` #[inline(always)] #[doc(alias = "literal")] #[doc(alias = "just")] #[doc(alias = "tag")] pubfn pattern<Input, Output, Count, Error: ParserError<(Input, usize)>>(
pattern: Output,
count: Count,
) -> impl Parser<(Input, usize), Output, Error> where
Input: Stream<Token = u8> + StreamIsPartial + Clone,
Count: ToUsize,
Output: From<u8>
+ AddAssign
+ Shl<usize, Output = Output>
+ Shr<usize, Output = Output>
+ PartialEq,
{ let count = count.to_usize();
trace("pattern", move |input: &mut (Input, usize)| { let start = input.checkpoint();
take(count).parse_next(input).and_then(|o| { if pattern == o {
Ok(o)
} else {
input.reset(&start);
Err(ParserError::from_input(input))
}
})
})
}
/// Parses one specific bit as a bool. /// /// # Effective Signature /// /// Assuming you are parsing a `(&[u8], usize)` bit [Stream]: /// ```rust /// # use winnow::prelude::*;; /// # use winnow::error::ContextError; /// pub fn bool(input: &mut (&[u8], usize)) -> ModalResult<bool> /// # { /// # winnow::binary::bits::bool.parse_next(input) /// # } /// ``` /// /// # Example /// /// ```rust /// # use winnow::prelude::*; /// # use winnow::Bytes; /// # use winnow::error::InputError; /// use winnow::binary::bits::bool; /// /// type Stream<'i> = &'i Bytes; /// /// fn stream(b: &[u8]) -> Stream<'_> { /// Bytes::new(b) /// } /// /// fn parse(input: &mut (Stream<'_>, usize)) -> ModalResult<bool> { /// bool.parse_next(input) /// } /// /// assert_eq!(parse.parse_peek((stream(&[0b10000000]), 0)), Ok(((stream(&[0b10000000]), 1), true))); /// assert_eq!(parse.parse_peek((stream(&[0b10000000]), 1)), Ok(((stream(&[0b10000000]), 2), false))); /// ``` #[doc(alias = "any")] pubfn bool<Input, Error: ParserError<(Input, usize)>>(
input: &mut (Input, usize),
) -> Result<bool, Error> where
Input: Stream<Token = u8> + StreamIsPartial + Clone,
{
trace("bool", |input: &mut (Input, usize)| { let bit: u32 = take(1usize).parse_next(input)?;
Ok(bit != 0)
})
.parse_next(input)
}
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.13Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-10-02)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.