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) -> SrcProduces 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,Syncand'staticbounds][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