macro_rules! do_gen {
    (__impl $i:expr, $idx:expr, ( $($rest:expr),* )) => { ... };
    (__impl $i:expr, $idx:expr, $e:ident( $($args:tt)* )) => { ... };
    (__impl $i:expr, $idx:expr, $submac:ident!( $($args:tt)* )) => { ... };
    (__impl $i:expr, $idx:expr, $e:ident >> $($rest:tt)*) => { ... };
    (__impl $i:expr, $idx:expr, $e:ident( $($args:tt)* ) >> $($rest:tt)*) => { ... };
    (__impl $i:expr, $idx:expr, $submac:ident!( $($args:tt)* ) >> $($rest:tt)*) => { ... };
    (__impl $i:expr, $idx:expr, $e:ident : $($rest:tt)*) => { ... };
    ( ($i:expr, $idx:expr), $($rest:tt)*) => { ... };
    ( $i:expr, $($rest:tt)*) => { ... };
}
Expand description

Applies sub-generators in a sequence.

do_gen!( I, I -> Result<I,E> >> I-> Result<I,E> >> ... >> I->Result<I,E>) => I -> Result<I,E> with I = (&[u8],usize) and E = GenError

The input type is a tuple (slice,index). The index is incremented by each generator, to reflect the number of bytes written.

If the input slice is not big enough, an error GenError::BufferTooSmall(n) is returned, n being the index that was required.


fn gen0(x:(&mut [u8],usize),v:u8,w:u8) -> Result<(&mut [u8],usize),GenError> {
  do_gen!((x.0,x.1), gen_be_u8!(v) >> gen_be_u8!(w))
}

let mut mem : [u8; 2] = [0; 2];
let s = &mut mem[..];
let expected = [1, 2];

match gen0((s,0), 1, 2) {
    Ok((b,idx)) => {
        assert_eq!(idx,expected.len());
        assert_eq!(&b[..],&expected[..]);
    },
    Err(e) => panic!("error {:?}",e),
}