pub fn to_fixed_bytes<const N: usize, T>(
value: &T,
) -> Result<FixedBytes<N>, Error>Expand description
Encode the given value to a fixed-size bytes using the default
Encoding.
use musli::{Decode, Encode, FixedBytes};
use musli::storage;
#[derive(Decode, Encode)]
struct Person {
name: String,
age: u32,
}
let data: FixedBytes<128> = storage::to_fixed_bytes(&Person {
name: "Aristotle".to_string(),
age: 61,
})?;
let person: Person = storage::from_slice(&data[..])?;
assert_eq!(person.name, "Aristotle");
assert_eq!(person.age, 61);