pub fn fold_many0_once<I, O, E, F, G, R>(f: F, init: R, g: G) -> impl FnOnce(I) -> IResult<I, R, E>
where
  I: Clone + PartialEq,
  F: Fn(I) -> IResult<I, O, E>,
  G: Fn(R, O) -> R,
  E: ParseError<I>,
{
  move |i: I| {
    let mut res = init;
    let mut input = i.clone();

    loop {
      let i_ = input.clone();
      match f(i_) {
        Ok((i, o)) => {
          // loop trip must always consume (otherwise infinite loops)
          if i == input {
            return Err(Err::Error(E::from_error_kind(input, ErrorKind::Many0)));
          }

          res = g(res, o);
          input = i;
        }
        Err(Err::Error(_)) => {
          return Ok((input, res));
        }
        Err(e) => {
          return Err(e);
        }
      }
    }
  }
}
/// This is a custom implementation of `nom::multi::fold_many0` that avoids the
/// `Clone` bound on the initial value for the accumlator. The function returns
/// an `impl FnOnce` type instead of nom's usual `impl Fn` to avoid having to
/// clone `init` despite being moved into the closure.
This is a custom implementation of `nom::multi::fold_many0` that avoids the
`Clone` bound on the initial value for the accumlator.
This is a custom implementation of ` nom :: multi :: fold_many0 ` that avoids the ` Clone ` bound on the initial value for the accumlator .
pub fn fold_many0_once<I, O, E, F, G, R>(f: F, init: R, g: G) -> impl FnOnce(I) -> IResult<I, R, E>
where
  I: Clone + PartialEq,
  F: Fn(I) -> IResult<I, O, E>,
  G: Fn(R, O) -> R,
  E: ParseError<I>,
{
  move |i: I| {
    let mut res = init;
    let mut input = i.clone();
    loop {
      let i_ = input.clone();
      match f(i_) {
        Ok((i, o)) => {
          // loop trip must always consume (otherwise infinite loops)
          if i == input {
            return Err(Err::Error(E::from_error_kind(input, ErrorKind::Many0)));
          }
          res = g(res, o);
          input = i;
        }
        Err(Err::Error(_)) => {
          return Ok((input, res));
        }
        Err(e) => {
          return Err(e);
        }
      }
    }
  }
}
pub fn fold_many0_once < I , O , E , F , G , R > ( f : F , init : R , g : G ) -> impl FnOnce ( I ) -> IResult < I , R , E > where I : Clone + PartialEq , F : Fn ( I ) -> IResult < I , O , E > , G : Fn ( R , O ) -> R , E : ParseError < I > , { move | i : I | { let mut res = init ; let mut input = i . clone ( ) ; loop { let i_ = input . clone ( ) ; match f ( i_ ) { Ok ( ( i , o ) ) => { // loop trip must always consume (otherwise infinite loops) if i == input { return Err ( Err :: Error ( E :: from_error_kind ( input , ErrorKind :: Many0 ) ) ) ; } res = g ( res , o ) ; input = i ; } Err ( Err :: Error ( _ ) ) => { return Ok ( ( input , res ) ) ; } Err ( e ) => { return Err ( e ) ; } } } } }
This is a custom implementation of `nom::multi::fold_many0` that avoids the
`Clone` bound on the initial value for the accumlator.
This is a custom implementation of ` nom :: multi :: fold_many0 ` that avoids the ` Clone ` bound on the initial value for the accumlator .
f
F
init
R
g
G
f
F
init
R
g
G