Function from_bytes
pub fn from_bytes<T, E>(bytes: &[u8]) -> Result<T, E> ⓘwhere
T: Archive,
<T as Archive>::Archived: for<'a> CheckBytes<Strategy<Validator<ArchiveValidator<'a>, SharedValidator>, E>> + Deserialize<T, Strategy<Pool, E>>,
E: Source,
Available on crate feature
dep_rkyv
only.Expand description
Deserialize a value from the given bytes.
This is a safe alternative to from_bytes_unchecked
and is part of the
high-level API.
§Example
use rkyv::{
from_bytes, rancor::Error, to_bytes, 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::<Error>(&value).unwrap();
let deserialized = from_bytes::<Example, Error>(&bytes).unwrap();
assert_eq!(deserialized, value);