Function cookie_factory::sequence::tuple

source ·
pub fn tuple<W: Write, List: Tuple<W>>(l: List) -> impl SerializeFn<W>
Expand description

Applies multiple serializers in sequence

Currently tuples up to 20 elements are supported.

use cookie_factory::{gen, sequence::tuple, combinator::string, bytes::be_u16};

let mut buf = [0u8; 100];

{
  let (buf, pos) = gen(
    tuple((
      string("abcd"),
      be_u16(0x20),
      string("efgh"),
    )),
    &mut buf[..]
  ).unwrap();
  assert_eq!(pos, 10);
  assert_eq!(buf.len(), 100 - 10);
}

assert_eq!(&buf[..10], &b"abcd\x00\x20efgh"[..]);