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

Constructs a new Unalign.

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.

Gets a copy of the inner T.

Trait Implementations

Gets the bytes of this value. Read more

Gets the bytes of this value mutably. Read more

Writes a copy of self to bytes. Read more

Writes a copy of self to the prefix of bytes. Read more

Writes a copy of self to the suffix of bytes. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Reads a copy of Self from bytes. Read more

Reads a copy of Self from the prefix of bytes. Read more

Reads a copy of Self from the suffix of bytes. Read more

Creates an instance of Self from zeroed bytes.

Creates a Box<Self> from zeroed bytes. Read more

Creates a Box<[Self]> (a boxed slice) from zeroed bytes. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.