pub fn to_slice<T>(out: &mut [u8], value: &T) -> Result<usize, Error>Expand description
Encode the given value to the given slice using the default
Encoding and return the number of bytes encoded.
ยงExamples
use musli::{Decode, Encode};
use musli::packed;
#[derive(Decode, Encode)]
struct Person {
name: String,
age: u32,
}
let mut data = Vec::new();
data.resize(128, 0);
let w = packed::to_slice(&mut data[..], &Person {
name: "Aristotle".to_string(),
age: 61,
})?;
assert!(w > 0);
let person: Person = packed::from_slice(&data[..w])?;
assert_eq!(person.name, "Aristotle");
assert_eq!(person.age, 61);