diff --git a/rust/src/common.rs b/rust/src/common.rs index 1d28ba5f0a..71eaad728f 100644 --- a/rust/src/common.rs +++ b/rust/src/common.rs @@ -1,6 +1,27 @@ use std::ffi::CString; use std::os::raw::c_char; +pub mod nom7 { + use nom7::bytes::streaming::{tag, take_until}; + use nom7::error::ParseError; + use nom7::IResult; + + /// Reimplementation of `take_until_and_consume` for nom 7 + /// + /// `take_until` does not consume the matched tag, and + /// `take_until_and_consume` was removed in nom 7. This function + /// provides an implementation (specialized for `&[u8]`). + pub fn take_until_and_consume<'a, E: ParseError<&'a [u8]>>(t: &'a [u8]) + -> impl Fn(&'a [u8]) -> IResult<&'a [u8], &'a [u8], E> + { + move |i: &'a [u8]| { + let (i, res) = take_until(t)(i)?; + let (i, _) = tag(t)(i)?; + Ok((i, res)) + } + } +} + #[macro_export] macro_rules! take_until_and_consume ( ( $i:expr, $needle:expr ) => (