Function rkyv::validation::validators::from_bytes
source · pub fn from_bytes<'a, T>(bytes: &'a [u8]) -> Result<T, FromBytesError<'a, T>>where
T: Archive,
T::Archived: 'a + CheckBytes<DefaultValidator<'a>> + Deserialize<T, SharedDeserializeMap>,
Expand description
Checks and deserializes a value from the given bytes.
This function is only available with the alloc
and validation
features because it uses a
general-purpose deserializer and performs validation on the data before deserializing. In
no-alloc and high-performance environments, the deserializer should be customized for the
specific situation.
§Examples
let value = vec![1, 2, 3, 4];
let bytes = rkyv::to_bytes::<_, 1024>(&value).expect("failed to serialize vec");
let deserialized = rkyv::from_bytes::<Vec<i32>>(&bytes).expect("failed to deserialize vec");
assert_eq!(deserialized, value);