Struct zerocopy::Unalign [−][src]
#[repr(C, packed)]pub struct Unalign<T>(_);
Expand description
A type with no alignment requirement.
A Unalign
wraps a T
, removing any alignment requirement. Unalign<T>
has the same size and ABI as T
, but not necessarily the same alignment.
This is useful if a type with an alignment requirement needs to be read from
a chunk of memory which provides no alignment guarantees.
Since Unalign
has no alignment requirement, the inner T
may not be
properly aligned in memory, and so Unalign
provides no way of getting a
reference to the inner T
. Instead, the T
may only be obtained by value
(see get
and into_inner
).
Implementations
Consumes self
, returning the inner T
.
Gets an unaligned raw pointer to the inner T
.
Safety
The returned raw pointer is not necessarily aligned to
align_of::<T>()
. Most functions which operate on raw pointers require
those pointers to be aligned, so calling those functions with the result
of get_ptr
will be undefined behavior if alignment is not guaranteed
using some out-of-band mechanism. In general, the only functions which
are safe to call with this pointer are which that are explicitly
documented as being sound to use with an unaligned pointer, such as
read_unaligned
.
Gets an unaligned mutable raw pointer to the inner T
.
Safety
The returned raw pointer is not necessarily aligned to
align_of::<T>()
. Most functions which operate on raw pointers require
those pointers to be aligned, so calling those functions with the result
of get_ptr
will be undefined behavior if alignment is not guaranteed
using some out-of-band mechanism. In general, the only functions which
are safe to call with this pointer are those which are explicitly
documented as being sound to use with an unaligned pointer, such as
read_unaligned
.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Unalign<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Unalign<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more