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
impl StructLike
sourcepub fn elements<'a>(&'a self) -> impl IterTrait<'a, FieldOrVariant<'a>> + 'a
pub fn elements<'a>(&'a self) -> impl IterTrait<'a, FieldOrVariant<'a>> + 'a
Returns an iterator over elements of the item.
sourcepub fn vis(&self) -> &Visibility
pub fn vis(&self) -> &Visibility
Returns an iterator over elements of the item.
sourcepub fn fields<'a>(&'a self) -> impl IterTrait<'a, &'a Field>
pub fn fields<'a>(&'a self) -> impl IterTrait<'a, &'a Field>
Returns an iterator over fields of the item.
sourcepub fn field_names<'a>(&'a self) -> Option<impl IterTrait<'a, &'a Ident> + '_>
pub fn field_names<'a>(&'a self) -> Option<impl IterTrait<'a, &'a Ident> + '_>
Extracts the name of each field.
sourcepub fn field_types<'a>(&'a self) -> impl IterTrait<'a, &'a Type>
pub fn field_types<'a>(&'a self) -> impl IterTrait<'a, &'a Type>
Extracts the type of each field.
sourcepub fn field_attrs<'a>(&'a self) -> impl IterTrait<'a, &'a Vec<Attribute>>
pub fn field_attrs<'a>(&'a self) -> impl IterTrait<'a, &'a Vec<Attribute>>
Extracts the name of each field.
sourcepub fn first_field(&self) -> Option<&Field>
pub fn first_field(&self) -> Option<&Field>
Extract the first field.
Trait Implementations§
source§impl Debug for StructLike
impl Debug for StructLike
source§impl From<ItemEnum> for StructLike
impl From<ItemEnum> for StructLike
source§impl From<ItemStruct> for StructLike
impl From<ItemStruct> for StructLike
source§fn from(item_struct: ItemStruct) -> Self
fn from(item_struct: ItemStruct) -> Self
Converts to this type from the input type.
source§impl Parse for StructLike
impl Parse for StructLike
fn parse(input: ParseStream<'_>) -> Result<Self>
source§impl PartialEq for StructLike
impl PartialEq for StructLike
source§fn eq(&self, other: &StructLike) -> bool
fn eq(&self, other: &StructLike) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl ToTokens for StructLike
impl ToTokens for StructLike
source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
impl StructuralPartialEq for StructLike
Auto Trait Implementations§
impl Freeze for StructLike
impl RefUnwindSafe for StructLike
impl !Send for StructLike
impl !Sync for StructLike
impl Unpin for StructLike
impl UnwindSafe for StructLike
Blanket Implementations§
source§impl<S> AssignWithType for S
impl<S> AssignWithType for S
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Spanned for Twhere
T: Spanned + ?Sized,
impl<T> Spanned for Twhere
T: Spanned + ?Sized,
source§fn span(&self) -> Span
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.