Function rkyv::util::from_bytes_unchecked

source ·
pub unsafe fn from_bytes_unchecked<T>(
    bytes: &[u8],
) -> Result<T, <SharedDeserializeMap as Fallible>::Error>
Expand description

Deserializes a value from the given bytes.

This function is only available with the alloc feature because it uses a general-purpose deserializer. In no-alloc and high-performance environments, the deserializer should be customized for the specific situation.

§Safety

  • The byte slice must represent an archived object
  • The root of the object must be stored at the end of the slice (this is the default behavior)

§Examples

let value = vec![1, 2, 3, 4];

let bytes = rkyv::to_bytes::<_, 1024>(&value).expect("failed to serialize vec");
// SAFETY:
// - The byte slice represents an archived object
// - The root of the object is stored at the end of the slice
let deserialized = unsafe {
    rkyv::from_bytes_unchecked::<Vec<i32>>(&bytes)
        .expect("failed to deserialize vec")
};

assert_eq!(deserialized, value);