Function cookie_factory::gen

source ·
pub fn gen<W: Write, F: SerializeFn<W>>(
    f: F,
    w: W
) -> Result<(W, u64), GenError>
Expand description

Runs the given serializer f with the Write impl w and returns the result

This internally wraps w in a WriteContext, starting at position 0.

use cookie_factory::{gen, combinator::slice};

let mut buf = [0u8; 100];

{
  let (buf, pos) = gen(slice(&b"abcd"[..]), &mut buf[..]).unwrap();
  assert_eq!(buf.len(), 100 - 4);
  assert_eq!(pos, 4);
}

assert_eq!(&buf[..4], &b"abcd"[..]);