Skip to main content

ValidateError

Enum ValidateError 

Source
pub enum ValidateError {
    OutOfBounds {
        addr: usize,
        need: usize,
        buf_len: usize,
    },
    Misaligned {
        addr: usize,
        align: usize,
    },
    NullNear {
        addr: usize,
    },
    InvalidListHeader {
        addr: usize,
    },
    ListLenMismatch {
        addr: usize,
        expected: u32,
        actual: u32,
    },
    InvalidDiscriminant {
        addr: usize,
        value: u8,
        max: u8,
    },
    InvalidBool {
        addr: usize,
        value: u8,
    },
    Uninhabited,
}
Expand description

Error returned by Flat::validate and Region::from_bytes.

Variants§

§

OutOfBounds

Buffer is too small to hold the type at the given address.

Fields

§addr: usize

Address of the value in the buffer.

§need: usize

Number of bytes needed.

§buf_len: usize

Actual buffer length.

§

Misaligned

Address is not correctly aligned for the type.

Fields

§addr: usize

Address that failed the alignment check.

§align: usize

Required alignment.

§

NullNear

A Near<T> offset is zero (null pointer).

Fields

§addr: usize

Address of the Near<T> field.

§

InvalidListHeader

NearList header has inconsistent head/len (e.g. non-zero head with zero len).

Fields

§addr: usize

Address of the NearList header.

§

ListLenMismatch

Segment lengths don’t sum to the total NearList length.

Fields

§addr: usize

Address of the NearList header.

§expected: u32

Expected total length from the header.

§actual: u32

Actual sum of segment lengths.

§

InvalidDiscriminant

Enum discriminant is not a valid variant.

Fields

§addr: usize

Address of the discriminant byte.

§value: u8

The discriminant value found.

§max: u8

Maximum valid discriminant (variant_count - 1).

§

InvalidBool

A bool value is not 0 or 1.

Fields

§addr: usize

Address of the bool.

§value: u8

The invalid value found.

§

Uninhabited

An uninhabited type (Infallible) can never be valid.

Implementations§

Source§

impl ValidateError

Source

pub fn check_bounds<T>(addr: usize, buf: &[u8]) -> Result<(), Self>

Check that buf has at least size_of::<T>() bytes starting at addr.

§Errors

Returns OutOfBounds if the buffer is too small.

Source

pub const fn check_align<T>(addr: usize) -> Result<(), Self>

Check that addr is aligned for T.

§Errors

Returns Misaligned if the address is not aligned.

Source

pub fn check<T>(addr: usize, buf: &[u8]) -> Result<(), Self>

Combined bounds + alignment check.

§Errors

Returns OutOfBounds or Misaligned.

Trait Implementations§

Source§

impl Clone for ValidateError

Source§

fn clone(&self) -> ValidateError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ValidateError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ValidateError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ValidateError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for ValidateError

Source§

fn eq(&self, other: &ValidateError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ValidateError

Source§

impl StructuralPartialEq for ValidateError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.