[][src]Macro nom::count_fixed

macro_rules! count_fixed {
    ($i:expr, $typ:ty, $submac:ident!( $($args:tt)* ), $count: expr) => { ... };
    ($i:expr, $typ: ty, $f:expr, $count: expr) => { ... };
}

count_fixed!(O, I -> IResult<I,O>, nb) => I -> IResult<I, [O; nb]> Applies the child parser a fixed number of times and returns a fixed size array The type must be specified and it must be Copy

 named!(counter< [&[u8]; 2] >, count_fixed!( &[u8], tag!( "abcd" ), 2 ) );
 // can omit the type specifier if returning slices
 // named!(counter< [&[u8]; 2] >, count_fixed!( tag!( "abcd" ), 2 ) );

 let a = b"abcdabcdabcdef";
 let b = b"abcdefgh";
 let res = [&b"abcd"[..], &b"abcd"[..]];

 assert_eq!(counter(&a[..]),Ok((&b"abcdef"[..], res)));
 assert_eq!(counter(&b[..]), Err(Err::Error(error_position!(&b[..], ErrorKind::Count))));