Function bincode_core::serialize_size [−][src]
pub fn serialize_size<T: Serialize + ?Sized, O: Options>(
value: &T,
options: O
) -> Result<usize, SerializeError<()>>
Return the size that serializing a given T
type would need to be stored. This is an optimized version of getting the length of the writer after it’s done writing.
let mut buffer = [0u8; 1000]; let mut writer = BufferWriter::new(&mut buffer); let options = DefaultOptions::new(); let value = "your data structure goes here"; serialize(value, &mut writer, options).unwrap(); let written_len = writer.written_len(); let measured_len = serialize_size(value, options).unwrap(); assert_eq!(written_len, measured_len);
But without actually writing to memory