[][src]Union alignas::AlignAs

#[repr(C)]
pub union AlignAs<T: Copy, A: Copy> { // some fields omitted }

Wrap an object of type T to give it the alignment requirements of an object of type A.

This has a similar effect to #[repr(align(...))], but is parameterized to support the creation of structures that are generic over alignment.

Example:

extern crate alignas;
use alignas::AlignAs;
use std::{mem, slice};

// put some byte data into the buffer
let mut buffer: AlignAs<_, u64> = AlignAs::new([0u8; 64]);
buffer[3..18].copy_from_slice(b"some input here");

// now do something with it that requires aligned access...
let mut ints = [0u64; 8];
let ptr = &buffer as *const _ as *const u64;
ints.copy_from_slice(unsafe { slice::from_raw_parts(ptr, 8) });

Methods

impl<T: Copy, A: Copy> AlignAs<T, A>
[src]

pub fn new(t: T) -> Self
[src]

Put the given T object into an aligned location

Trait Implementations

impl<T: Copy + Copy, A: Copy + Copy> Copy for AlignAs<T, A>
[src]

impl<T: Copy, A: Copy> DerefMut for AlignAs<T, A>
[src]

impl<T: Copy, A: Copy> Deref for AlignAs<T, A>
[src]

type Target = T

The resulting type after dereferencing.

impl<T: Display + Copy, A: Copy> Display for AlignAs<T, A>
[src]

impl<T: Debug + Copy, A: Copy> Debug for AlignAs<T, A>
[src]

impl<T: PartialEq + Copy, A: Copy> PartialEq<AlignAs<T, A>> for AlignAs<T, A>
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl<T: Eq + Copy, A: Copy> Eq for AlignAs<T, A>
[src]

impl<T: Ord + Copy, A: Copy> Ord for AlignAs<T, A>
[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<T: PartialOrd + Copy, A: Copy> PartialOrd<AlignAs<T, A>> for AlignAs<T, A>
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T: Hash + Copy, A: Copy> Hash for AlignAs<T, A>
[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: Copy + Clone + Copy, A: Copy + Clone + Copy> Clone for AlignAs<T, A>
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Default + Copy, A: Copy> Default for AlignAs<T, A>
[src]

Auto Trait Implementations

impl<T, A> Send for AlignAs<T, A> where
    A: Send,
    T: Send

impl<T, A> Sync for AlignAs<T, A> where
    A: Sync,
    T: Sync

Blanket Implementations

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

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

The type returned in the event of a conversion error.

impl<T> From for T
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

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

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]