encode

Function encode 

Source
pub fn encode<W, T>(writer: W, value: &T) -> Result<W::Ok, Error>
where W: IntoWriter, T: ?Sized + Encode<Binary>,
Expand description

Encode the given value to the given Writer using the default Encoding.

ยงExamples

use musli::{Decode, Encode};
use musli::storage;

#[derive(Decode, Encode)]
struct Person {
    name: String,
    age: u32,
}

let mut data = Vec::new();

storage::encode(&mut data, &Person {
    name: "Aristotle".to_string(),
    age: 61,
})?;

let person: Person = storage::from_slice(&data[..])?;
assert_eq!(person.name, "Aristotle");
assert_eq!(person.age, 61);