devela::_dep::rkyv::bytecheck

Trait Verify

pub unsafe trait Verify<C>
where C: Fallible + ?Sized,
{ // Required method fn verify(&self, context: &mut C) -> Result<(), <C as Fallible>::Error> ; }
Available on crate feature dep_rkyv only.
Expand description

A type that can check whether its invariants are upheld.

When using the derive, adding #[bytecheck(verify)] allows implementing Verify for the derived type. Verify::verify will be called after the type is checked and all fields are known to be valid.

§Safety

  • verify must only return Ok if all of the invariants of this type are upheld by self.
  • verify may not assume that its type invariants are upheld by the given self (the invariants of each field are guaranteed to be upheld).

§Example

use core::{error::Error, fmt};

use bytecheck::{CheckBytes, Verify};
use rancor::{fail, Fallible, Source};

#[derive(CheckBytes)]
#[bytecheck(verify)]
#[repr(C, align(4))]
pub struct NonMaxU32(u32);

unsafe impl<C: Fallible + ?Sized> Verify<C> for NonMaxU32
where
    C::Error: Source,
{
    fn verify(&self, context: &mut C) -> Result<(), C::Error> {
        #[derive(Debug)]
        struct NonMaxCheckError;

        impl fmt::Display for NonMaxCheckError {
            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                write!(f, "non-max u32 was set to u32::MAX")
            }
        }

        impl Error for NonMaxCheckError {}

        if self.0 == u32::MAX {
            fail!(NonMaxCheckError);
        }

        Ok(())
    }
}

Required Methods§

fn verify(&self, context: &mut C) -> Result<(), <C as Fallible>::Error>

Checks whether the invariants of this type are upheld by self.

Implementors§

§

impl<C> Verify<C> for ArchivedCString

§

impl<C> Verify<C> for ArchivedString

§

impl<C> Verify<C> for ArchivedDuration
where C: Fallible + ?Sized, <C as Fallible>::Error: Source,

§

impl<C, K, V, H> Verify<C> for ArchivedIndexMap<K, V, H>
where C: Fallible + ArchiveContext + ?Sized, <C as Fallible>::Error: Source, K: CheckBytes<C>, V: CheckBytes<C>,

§

impl<C, K, V, const E: usize> Verify<C> for ArchivedBTreeMap<K, V, E>
where C: Fallible + ArchiveContext + ?Sized, <C as Fallible>::Error: Source, K: CheckBytes<C>, V: CheckBytes<C>,

§

impl<C, T> Verify<C> for ArchivedHashTable<T>
where C: Fallible + ArchiveContext + ?Sized, <C as Fallible>::Error: Source, T: CheckBytes<C>,

§

impl<T, C> Verify<C> for ArchivedBox<T>

§

impl<T, C> Verify<C> for ArchivedVec<T>
where T: CheckBytes<C>, C: Fallible + ArchiveContext + ?Sized, <C as Fallible>::Error: Source,

§

impl<T, F, C> Verify<C> for ArchivedRc<T, F>

§

impl<T, F, C> Verify<C> for ArchivedRcWeak<T, F>