pub fn object_length<T>(value: &T) -> Result<usize>where
T: BorshSerialize + ?Sized,
Expand description
Serializes an object without allocation to compute and return its length
ยงExample
use borsh::BorshSerialize;
/// derive is only available if borsh is built with `features = ["derive"]`
#[derive(BorshSerialize)]
struct A {
tag: String,
value: u64,
};
let a = A { tag: "hello".to_owned(), value: 42 };
assert_eq!(8, borsh::object_length(&12u64).unwrap());
assert_eq!(17, borsh::object_length(&a).unwrap());