Struct ValidityError

struct ValidityError<Src, Dst: ?Sized + TryFromBytes> { ... }

The error emitted if the conversion source contains invalid data.

Implementations

impl<Src, Dst: ?Sized + TryFromBytes> ValidityError<Src, Dst>

fn into_src(self: Self) -> Src

Produces the source underlying the failed conversion.

fn map_src<NewSrc, impl FnOnce(Src) -> NewSrc: FnOnce(Src) -> NewSrc>(self: Self, f: impl FnOnce(Src) -> NewSrc) -> ValidityError<NewSrc, Dst>

Maps the source value associated with the conversion error.

This can help mitigate [issues with Send, Sync and 'static bounds][self#send-sync-and-static].

Examples

use zerocopy::*;

let source: u8 = 42;

// Try to transmute the `source` to a `bool`. This will fail.
let maybe_bool: Result<bool, ValidityError<u8, bool>> = try_transmute!(source);

// Drop the error's source.
let maybe_bool: Result<bool, ValidityError<(), bool>> = maybe_bool.map_err(|err| {
    err.map_src(drop)
});

impl<Src, Dst> Display for ValidityError<Src, Dst>

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

impl<Src, Dst> Error for ValidityError<Src, Dst>

impl<Src, Dst> Freeze for ValidityError<Src, Dst>

impl<Src, Dst> RefUnwindSafe for ValidityError<Src, Dst>

impl<Src, Dst> Send for ValidityError<Src, Dst>

impl<Src, Dst> Sync for ValidityError<Src, Dst>

impl<Src, Dst> Unpin for ValidityError<Src, Dst>

impl<Src, Dst> UnsafeUnpin for ValidityError<Src, Dst>

impl<Src, Dst> UnwindSafe for ValidityError<Src, Dst>

impl<Src, Dst: ?Sized + TryFromBytes> Debug for ValidityError<Src, Dst>

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

impl<Src: Clone, Dst: ?Sized + TryFromBytes> Clone for ValidityError<Src, Dst>

fn clone(self: &Self) -> Self

impl<Src: Eq, Dst: ?Sized + TryFromBytes> Eq for ValidityError<Src, Dst>

impl<Src: PartialEq, Dst: ?Sized + TryFromBytes> PartialEq for ValidityError<Src, Dst>

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

impl<T> Any for ValidityError<Src, Dst>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ValidityError<Src, Dst>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ValidityError<Src, Dst>

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

impl<T> CloneToUninit for ValidityError<Src, Dst>

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

impl<T> From for ValidityError<Src, Dst>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for ValidityError<Src, Dst>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for ValidityError<Src, Dst>

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

impl<T, U> TryInto for ValidityError<Src, Dst>

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