Function cookie_factory::combinator::cond
source · pub fn cond<F, W: Write>(condition: bool, f: F) -> impl SerializeFn<W>where
F: SerializeFn<W>,
Expand description
Applies a serializer if the condition is true
use cookie_factory::{gen, combinator::{cond, string}};
let mut buf = [0u8; 100];
{
let (buf, pos) = gen(cond(true, string("abcd")), &mut buf[..]).unwrap();
assert_eq!(pos, 4);
assert_eq!(buf.len(), 100 - 4);
}
assert_eq!(&buf[..4], &b"abcd"[..]);