Function to_bytes_with_alloc
pub fn to_bytes_with_alloc<A, E>(
value: &impl Serialize<Strategy<Serializer<AlignedVec, A, Share>, E>>,
alloc: A,
) -> Result<AlignedVec, E> ⓘ
Available on crate feature
dep_rkyv
only.Expand description
Serialize a value using the given allocator.
This is part of the high-level API.
§Example
use rkyv::{
api::high::to_bytes_with_alloc, from_bytes, rancor::Error,
util::with_arena, Archive, Deserialize, Serialize,
};
#[derive(Archive, Serialize, Deserialize, Debug, PartialEq)]
struct Example {
name: String,
value: i32,
}
let value = Example {
name: "pi".to_string(),
value: 31415926,
};
with_arena(|arena| {
let bytes =
to_bytes_with_alloc::<_, Error>(&value, arena.acquire()).unwrap();
let deserialized = from_bytes::<Example, Error>(&bytes).unwrap();
assert_eq!(deserialized, value);
});