Repr

Enum Repr 

Source
pub(crate) enum Repr<Prim, Packed> {
    Transparent(Span),
    Compound(Spanned<CompoundRepr<Prim>>, Option<Spanned<AlignRepr<Packed>>>),
}
Expand description

The computed representation of a type.

This is the result of processing all #[repr(...)] attributes on a type, if any. A Repr is only capable of representing legal combinations of #[repr(...)] attributes.

Variants§

§

Transparent(Span)

#[repr(transparent)]

§

Compound(Spanned<CompoundRepr<Prim>>, Option<Spanned<AlignRepr<Packed>>>)

A compound representation: repr(C), repr(Rust), or repr(Int) optionally combined with repr(packed(...)) or repr(align(...))

Implementations§

Source§

impl<Prim, Packed> Repr<Prim, Packed>

Source

pub(crate) fn repr_type_name(&self) -> &str
where Prim: Copy + With<PrimitiveRepr>,

Gets the name of this “repr type” - the non-align repr(X) that is used in prose to refer to this type.

For example, we would refer to #[repr(C, align(4))] struct Foo { ... } as a “repr(C) struct”.

Source

pub(crate) fn is_transparent(&self) -> bool

Source

pub(crate) fn is_c(&self) -> bool

Source

pub(crate) fn is_primitive(&self) -> bool

Source

pub(crate) fn get_packed(&self) -> Option<&Packed>

Source

pub(crate) fn get_align(&self) -> Option<Spanned<NonZeroU32>>

Source

pub(crate) fn is_align_gt_1(&self) -> bool

Source

pub(crate) fn unaligned_validate_no_align_gt_1(&self) -> Result<(), Error>

When deriving Unaligned, validate that the decorated type has no #[repr(align(N))] attribute where N > 1. If no such attribute exists (including if N == 1), this returns Ok(()), and otherwise it returns a descriptive error.

Source§

impl<Prim> Repr<Prim, NonZeroU32>

Source

pub(crate) fn is_packed_1(&self) -> bool

Does self describe a #[repr(packed)] or #[repr(packed(1))] type?

Source§

impl<Packed> Repr<PrimitiveRepr, Packed>

Source

fn get_primitive(&self) -> Option<&PrimitiveRepr>

Source

pub(crate) fn is_u8(&self) -> bool

Does self describe a #[repr(u8)] type?

Source

pub(crate) fn is_i8(&self) -> bool

Does self describe a #[repr(i8)] type?

Source§

impl<Prim, Packed> Repr<Prim, Packed>

Source

fn from_attrs_inner( attrs: &[Attribute], ) -> Result<Repr<Prim, Packed>, Spanned<FromAttrsError>>
where Prim: With<PrimitiveRepr>, Packed: With<NonZeroU32>,

Source§

impl<Prim, Packed> Repr<Prim, Packed>

Source

pub(crate) fn from_attrs( attrs: &[Attribute], ) -> Result<Repr<Prim, Packed>, Error>
where Prim: With<PrimitiveRepr>, Packed: With<NonZeroU32>,

Trait Implementations§

Source§

impl<Prim, Packed> ToTokens for Repr<Prim, Packed>
where Prim: With<PrimitiveRepr> + Copy, Packed: With<NonZeroU32> + Copy,

Source§

fn to_tokens(&self, ts: &mut TokenStream)

Write self to the given TokenStream. Read more
Source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
Source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. Read more

Auto Trait Implementations§

§

impl<Prim, Packed> Freeze for Repr<Prim, Packed>
where Prim: Freeze, Packed: Freeze,

§

impl<Prim, Packed> RefUnwindSafe for Repr<Prim, Packed>
where Prim: RefUnwindSafe, Packed: RefUnwindSafe,

§

impl<Prim, Packed> !Send for Repr<Prim, Packed>

§

impl<Prim, Packed> !Sync for Repr<Prim, Packed>

§

impl<Prim, Packed> Unpin for Repr<Prim, Packed>
where Prim: Unpin, Packed: Unpin,

§

impl<Prim, Packed> UnwindSafe for Repr<Prim, Packed>
where Prim: UnwindSafe, Packed: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> Spanned for T
where T: Spanned + ?Sized,

Source§

fn span(&self) -> Span

Returns a Span covering the complete contents of this syntax tree node, or Span::call_site() if this node is empty.
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.