Function deserialize
pub fn deserialize<T, E>(
value: &impl Deserialize<T, Strategy<(), E>>,
) -> Result<T, E> ⓘ
Available on crate feature
dep_rkyv
only.Expand description
Deserialize a value from the given archived value.
This is part of the low-level API.
§Example
use core::mem::MaybeUninit;
use rkyv::{
access_unchecked,
api::low::{deserialize, to_bytes_in_with_alloc},
rancor::Failure,
ser::{allocator::SubAllocator, writer::Buffer},
util::Align,
with::InlineAsBox,
Archive, Deserialize, Serialize,
};
let mut output = Align([MaybeUninit::<u8>::uninit(); 256]);
let mut alloc = [MaybeUninit::<u8>::uninit(); 256];
#[derive(Archive, Serialize, Deserialize, Debug, PartialEq)]
struct Example {
inner: i32,
}
let value = Example { inner: 42 };
let bytes = to_bytes_in_with_alloc::<_, _, Failure>(
&value,
Buffer::from(&mut *output),
SubAllocator::new(&mut alloc),
)
.unwrap();
let archived = unsafe { access_unchecked::<ArchivedExample>(&*bytes) };
let deserialized = deserialize::<Example, Failure>(archived).unwrap();
assert_eq!(value, deserialized);