pub fn encode<T: Serialize + ?Sized>(value: &T) -> Result<Vec<u8>>Expand description
Encode value into a freshly allocated Vec<u8>.
This is the Tier-1 entry point — the one-line surface for the common
case. Allocates one buffer with room for 512 bytes up front (measured
faster than an exact-size pre-pass), which grows if the value is larger.
To allocate exactly once at the exact size, use
Encoder::with_capacity(value.encoded_len()?).
§Examples
let bytes = pack_io::encode(&42_u64).unwrap();
let back: u64 = pack_io::decode(&bytes).unwrap();
assert_eq!(back, 42);§Errors
Propagates any error returned by the type’s Serialize implementation.
The built-in primitive and collection impls never error on an in-memory
encoder.