Macro peel_ip::prelude::count_fixed
[−]
macro_rules! count_fixed { ( $ i : expr , $ typ : ty , $ submac : ident ! ( $ ( $ args : tt ) * ) , $ count : expr ) => { ... }; ( $ i : expr , $ typ : ty , $ f : ident , $ 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[..]), Done(&b"abcdef"[..], res)); assert_eq!(counter(&b[..]), Error(error_position!(ErrorKind::Count, &b[..])));