devela::_dep::rkyv::api::high

Function to_bytes_in

pub fn to_bytes_in<W, E>(
    value: &impl for<'a> Serialize<Strategy<Serializer<W, ArenaHandle<'a>, Share>, E>>,
    writer: W,
) -> Result<W, E> 
where W: Writer<E>, E: Source,
Available on crate feature dep_rkyv only.
Expand description

Serialize a value and write the bytes to the given writer.

This is part of the high-level API.

§Example

use rkyv::{
    api::high::to_bytes_in, from_bytes, rancor::Error, util::AlignedVec,
    Archive, Deserialize, Serialize,
};

#[derive(Archive, Serialize, Deserialize, Debug, PartialEq)]
struct Example {
    name: String,
    value: i32,
}

let value = Example {
    name: "pi".to_string(),
    value: 31415926,
};

let bytes =
    to_bytes_in::<_, Error>(&value, AlignedVec::<8>::new()).unwrap();
let deserialized = from_bytes::<Example, Error>(&bytes).unwrap();

assert_eq!(deserialized, value);