pub struct AlignmentError<Src, Dst: ?Sized> {
src: Src,
dst: SendSyncPhantomData<Dst>,
}
Expand description
The error emitted if the conversion source is improperly aligned.
Fields§
§src: Src
The source value involved in the conversion.
dst: SendSyncPhantomData<Dst>
The inner destination type inolved in the conversion.
INVARIANT: An AlignmentError
may only be constructed if Dst
’s
alignment requirement is greater than one.
Implementations§
Source§impl<Src, Dst: ?Sized> AlignmentError<Src, Dst>
impl<Src, Dst: ?Sized> AlignmentError<Src, Dst>
Sourcepub(crate) unsafe fn new_unchecked(src: Src) -> Self
pub(crate) unsafe fn new_unchecked(src: Src) -> Self
§Safety
The caller must ensure that Dst
’s alignment requirement is greater
than one.
pub(crate) fn with_src<NewSrc>( self, new_src: NewSrc, ) -> AlignmentError<NewSrc, Dst>
Sourcepub fn map_src<NewSrc>(
self,
f: impl FnOnce(Src) -> NewSrc,
) -> AlignmentError<NewSrc, Dst>
pub 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.
§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)
});
pub(crate) fn into<S, V>(self) -> ConvertError<Self, S, V>
Sourcefn display_verbose_extras(&self, f: &mut Formatter<'_>) -> Resultwhere
Src: Deref,
Dst: KnownLayout,
fn display_verbose_extras(&self, f: &mut Formatter<'_>) -> Resultwhere
Src: Deref,
Dst: KnownLayout,
Format extra details for a verbose, human-readable error message.
This formatting may include potentially sensitive information.
Trait Implementations§
Source§impl<Src, Dst: ?Sized> Debug for AlignmentError<Src, Dst>
impl<Src, Dst: ?Sized> Debug for AlignmentError<Src, Dst>
Source§impl<Src, Dst> Display for AlignmentError<Src, Dst>
Produces a human-readable error message.
impl<Src, Dst> Display for AlignmentError<Src, Dst>
Produces a human-readable error message.
The message differs between debug and release builds. When
debug_assertions
are enabled, this message is verbose and includes
potentially sensitive information.