Struct s2n_codec::zerocopy::Unalign

source ·
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§

source§

impl<T> Unalign<T>

source

pub fn new(val: T) -> Unalign<T>

Constructs a new Unalign.

source

pub fn into_inner(self) -> T

Consumes self, returning the inner T.

source

pub fn get_ptr(&self) -> *const 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.

source

pub fn get_mut_ptr(&mut self) -> *mut T

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.

source§

impl<T> Unalign<T>where T: Copy,

source

pub fn get(&self) -> T

Gets a copy of the inner T.

Trait Implementations§

source§

impl<T> AsBytes for Unalign<T>where T: AsBytes,

source§

fn as_bytes(&self) -> &[u8]

Gets the bytes of this value. Read more
source§

fn write_to<B>(&self, bytes: B) -> Option<()>where B: ByteSliceMut,

Writes a copy of self to bytes. Read more
source§

fn write_to_prefix<B>(&self, bytes: B) -> Option<()>where B: ByteSliceMut,

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

fn write_to_suffix<B>(&self, bytes: B) -> Option<()>where B: ByteSliceMut,

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

impl<T> Clone for Unalign<T>where T: Copy,

source§

fn clone(&self) -> Unalign<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> FromBytes for Unalign<T>where T: FromBytes,

source§

fn read_from<B>(bytes: B) -> Option<Self>where B: ByteSlice, Self: Sized,

Reads a copy of Self from bytes. Read more
source§

fn read_from_prefix<B>(bytes: B) -> Option<Self>where B: ByteSlice, Self: Sized,

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

fn read_from_suffix<B>(bytes: B) -> Option<Self>where B: ByteSlice, Self: Sized,

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

fn new_zeroed() -> Selfwhere Self: Sized,

Creates an instance of Self from zeroed bytes.
source§

impl<T> Copy for Unalign<T>where T: Copy,

source§

impl<T> Unaligned for Unalign<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Unalign<T>where T: RefUnwindSafe,

§

impl<T> Send for Unalign<T>where T: Send,

§

impl<T> Sync for Unalign<T>where T: Sync,

§

impl<T> Unpin for Unalign<T>where T: Unpin,

§

impl<T> UnwindSafe for Unalign<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.