Struct AlignAs

#[repr(C)]
pub struct AlignAs<B: ?Sized, T> { pub _align: [T; 0], pub bytes: B }

A hack to align a smaller type B with a bigger type T.

The usual use of this is with B = [u8] and T = u32. That is, it permits aligning a sequence of bytes on a 4-byte boundary. This is useful in contexts where one wants to embed a serialized dense DFA into a Rust a program while guaranteeing the alignment required for the DFA.

See dense::DFA::from_bytes for an example of how to use this type.

Fields

_align: [T; 0]

A zero-sized field indicating the alignment we want.

bytes: B

A possibly non-sized field containing a sequence of bytes.

Trait Implementations

impl<B: Debug + ?Sized, T: Debug> Debug for AlignAs<B, T>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl<B, T> Freeze for AlignAs<B, T> where [T; 0]: Freeze, B: Freeze + ?Sized,

impl<B, T> RefUnwindSafe for AlignAs<B, T> where [T; 0]: RefUnwindSafe, B: RefUnwindSafe + ?Sized,

impl<B, T> Send for AlignAs<B, T> where [T; 0]: Send, B: Send + ?Sized,

impl<B, T> Sync for AlignAs<B, T> where [T; 0]: Sync, B: Sync + ?Sized,

impl<B, T> Unpin for AlignAs<B, T> where [T; 0]: Unpin, B: Unpin + ?Sized,

impl<B, T> UnsafeUnpin for AlignAs<B, T> where [T; 0]: UnsafeUnpin, B: UnsafeUnpin + ?Sized,

impl<B, T> UnwindSafe for AlignAs<B, T> where [T; 0]: UnwindSafe, B: UnwindSafe + ?Sized,

Blanket Implementations

impl<T> Any for AlignAs<B, T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for AlignAs<B, T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for AlignAs<B, T> where T: ?Sized,

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

impl<T> From<T> for AlignAs<B, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for AlignAs<B, T> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom<U> for AlignAs<B, T> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for AlignAs<B, T> where U: TryFrom<T>,

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