Function from_bytes_unchecked
pub unsafe fn from_bytes_unchecked<T, E>(bytes: &[u8]) -> Result<T, E> ⓘ
Available on crate feature
dep_rkyv
only.Expand description
Deserialize a value from the given bytes.
This function does not check that the data is valid. Use from_bytes
to
validate the data instead.
This is part of the high-level API.
§Safety
The byte slice must represent a valid archived type when accessed at the default root position. See the module docs for more information.
§Example
use rkyv::{
from_bytes_unchecked, 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 =
unsafe { from_bytes_unchecked::<Example, Error>(&bytes).unwrap() };
assert_eq!(deserialized, value);