Struct AlignmentError

pub struct AlignmentError<Src, Dst: ?Sized> { /* private fields */ }

The error emitted if the conversion source is improperly aligned.

Implementations

impl<Src, Dst: ?Sized> AlignmentError<Src, Dst>

fn into_src(self) -> Src

Produces the source underlying the failed conversion.

fn map_src<NewSrc>(self, f: impl FnOnce(Src) -> NewSrc) -> AlignmentError<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 unaligned = Unalign::new(0u16);

// Attempt to deref `unaligned`. This might fail with an alignment error.
let maybe_n: Result<&u16, AlignmentError<&Unalign<u16>, u16>> = unaligned.try_deref();

// Map the error's source to its address as a usize.
let maybe_n: Result<&u16, AlignmentError<usize, u16>> = maybe_n.map_err(|err| {
    err.map_src(|src| src as *const _ as usize)
});

Trait Implementations

impl<Src, Dst> Display for AlignmentError<Src, Dst> where Src: Deref, Dst: KnownLayout + ?Sized,

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

impl<Src, Dst> Error for AlignmentError<Src, Dst> where Src: Deref, Dst: KnownLayout + ?Sized,

impl<Src, Dst: ?Sized> Debug for AlignmentError<Src, Dst>

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

impl<Src: Clone, Dst: ?Sized> Clone for AlignmentError<Src, Dst>

fn clone(&self) -> Self

impl<Src: Eq, Dst: ?Sized> Eq for AlignmentError<Src, Dst>

impl<Src: PartialEq, Dst: ?Sized> PartialEq for AlignmentError<Src, Dst>

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

Auto Trait Implementations

impl<Src, Dst> Freeze for AlignmentError<Src, Dst> where Src: Freeze, SendSyncPhantomData<Dst>: Freeze, Dst: ?Sized,

impl<Src, Dst> RefUnwindSafe for AlignmentError<Src, Dst> where Src: RefUnwindSafe, SendSyncPhantomData<Dst>: RefUnwindSafe, Dst: ?Sized,

impl<Src, Dst> Send for AlignmentError<Src, Dst> where Src: Send, SendSyncPhantomData<Dst>: Send, Dst: ?Sized,

impl<Src, Dst> Sync for AlignmentError<Src, Dst> where Src: Sync, SendSyncPhantomData<Dst>: Sync, Dst: ?Sized,

impl<Src, Dst> Unpin for AlignmentError<Src, Dst> where Src: Unpin, SendSyncPhantomData<Dst>: Unpin, Dst: ?Sized,

impl<Src, Dst> UnsafeUnpin for AlignmentError<Src, Dst> where Src: UnsafeUnpin, SendSyncPhantomData<Dst>: UnsafeUnpin, Dst: ?Sized,

impl<Src, Dst> UnwindSafe for AlignmentError<Src, Dst> where Src: UnwindSafe, SendSyncPhantomData<Dst>: UnwindSafe, Dst: ?Sized,

Blanket Implementations

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for AlignmentError<Src, Dst> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for AlignmentError<Src, Dst> where T: ?Sized,

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

impl<T> CloneToUninit for AlignmentError<Src, Dst> where T: Clone,

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

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

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for AlignmentError<Src, Dst> where U: From<T>,

fn into(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<U> for AlignmentError<Src, Dst> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for AlignmentError<Src, Dst> where U: TryFrom<T>,

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