Function check_pos_with_context
pub fn check_pos_with_context<T, C, E>(
bytes: &[u8],
pos: usize,
context: &mut C,
) -> Result<(), E> ⓘwhere
T: CheckBytes<Strategy<C, E>> + Pointee<Metadata = ()>,
C: ArchiveContext<E> + ?Sized,
E: Source,
Available on crate feature
dep_rkyv
only.Expand description
Check a byte slice with a given root position and context.
Most of the time, access
is a more ergonomic way to check and access a
byte slice.
§Example
use rkyv::{
api::{check_pos_with_context, root_position},
rancor::Error,
to_bytes,
validation::{
archive::ArchiveValidator, shared::SharedValidator, Validator,
},
Archive, Deserialize, Serialize,
};
#[derive(Archive, Serialize, Deserialize)]
struct Example {
name: String,
value: i32,
}
let value = Example {
name: "pi".to_string(),
value: 31415926,
};
let bytes = to_bytes::<Error>(&value).unwrap();
check_pos_with_context::<ArchivedExample, _, Error>(
&*bytes,
root_position::<ArchivedExample>(bytes.len()),
&mut Validator::new(
ArchiveValidator::new(&*bytes),
SharedValidator::new(),
),
)
.unwrap();