Enum macro_tools::exposed::struct_like::StructLike

source ·
pub enum StructLike {
    Unit(ItemStruct),
    Struct(ItemStruct),
    Enum(ItemEnum),
}
Expand description

Represents various struct-like constructs in Rust code.

This enum enables differentiation among unit types, structs, and enums, allowing for syntactic analysis and manipulation within macros. StructLike is designed to be used in macro contexts where behaviors may vary based on the struct-like type being processed.

Variants:

  • Unit: Represents unit structs, which are types without any fields or data. Useful in scenarios where a type needs to exist but does not hold any data itself, typically used for type-safe markers.
  • Struct: Represents regular Rust structs that contain fields. This variant is used to handle data structures that hold multiple related data pieces together in a named format.
  • Enum: Represents enums in Rust, which are types that can hold one of multiple possible variants. This is particularly useful for type-safe state or option handling without the use of external discriminators.

Variants§

§

Unit(ItemStruct)

A unit struct with no fields.

§

Struct(ItemStruct)

A typical Rust struct with named fields.

§

Enum(ItemEnum)

A Rust enum, which can be one of several defined variants.

Implementations§

source§

impl StructLike

source

pub fn elements<'a>(&'a self) -> impl IterTrait<'a, FieldOrVariant<'a>> + 'a

Returns an iterator over elements of the item.

source

pub fn attrs(&self) -> &Vec<Attribute>

Returns an iterator over elements of the item.

source

pub fn vis(&self) -> &Visibility

Returns an iterator over elements of the item.

source

pub fn ident(&self) -> &Ident

Returns an iterator over elements of the item.

source

pub fn generics(&self) -> &Generics

Returns an iterator over elements of the item.

source

pub fn fields<'a>(&'a self) -> impl IterTrait<'a, &'a Field>

Returns an iterator over fields of the item.

source

pub fn field_names<'a>(&'a self) -> Option<impl IterTrait<'a, &'a Ident> + '_>

Extracts the name of each field.

source

pub fn field_types<'a>(&'a self) -> impl IterTrait<'a, &'a Type>

Extracts the type of each field.

source

pub fn field_attrs<'a>(&'a self) -> impl IterTrait<'a, &'a Vec<Attribute>>

Extracts the name of each field.

source

pub fn first_field(&self) -> Option<&Field>

Extract the first field.

Trait Implementations§

source§

impl Debug for StructLike

source§

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

Formats the value using the given formatter. Read more
source§

impl From<ItemEnum> for StructLike

source§

fn from(item_enum: ItemEnum) -> Self

Converts to this type from the input type.
source§

impl From<ItemStruct> for StructLike

source§

fn from(item_struct: ItemStruct) -> Self

Converts to this type from the input type.
source§

impl Parse for StructLike

source§

fn parse(input: ParseStream<'_>) -> Result<Self>

source§

impl PartialEq for StructLike

source§

fn eq(&self, other: &StructLike) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToTokens for StructLike

source§

fn to_tokens(&self, tokens: &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
source§

impl StructuralPartialEq for StructLike

Auto Trait Implementations§

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<S> AssignWithType for S

source§

fn assign_with_type<T, IntoT>(&mut self, component: IntoT)
where IntoT: Into<T>, S: Assign<T, IntoT>,

Sets the value of a component by its type. 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>,

§

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>,

§

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.