pub fn calc_size<T, P>(value: &T, _params: P) -> Result<usize>Expand description
Calculate exact size of serialized data for a serde::Serialize value.
Useful for calculating exact size of serialized objects for buffer allocations.
Calculation process is inexpensive, for fixed-size objects it evaluates to compile-time
constant, or a few len() method calls for variable-size objects.
#[derive(serde_derive::Serialize)]
struct Foo(u16, String);
let foo = Foo(1, "abc".to_string());
let data_size = calc_size(&foo, params::AscendingOrder).unwrap();
assert_eq!(data_size, 6);