ast_enum_of_structs! { /// Data stored within an enum variant or struct. /// /// # Syntax tree enum /// /// This type is a [syntax tree enum]. /// /// [syntax tree enum]: crate::expr::Expr#syntax-tree-enums #[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))] pubenum Fields { /// Named fields of a struct or struct variant such as `Point { x: f64, /// y: f64 }`.
Named(FieldsNamed),
/// Unnamed fields of a tuple struct or tuple variant such as `Some(T)`.
Unnamed(FieldsUnnamed),
/// Unit struct or unit variant such as `None`.
Unit,
}
}
ast_struct! { /// Named fields of a struct or struct variant such as `Point { x: f64, /// y: f64 }`. #[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))] pubstruct FieldsNamed { pub brace_token: token::Brace, pub named: Punctuated<Field, Token![,]>,
}
}
ast_struct! { /// Unnamed fields of a tuple struct or tuple variant such as `Some(T)`. #[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))] pubstruct FieldsUnnamed { pub paren_token: token::Paren, pub unnamed: Punctuated<Field, Token![,]>,
}
}
impl Fields { /// Get an iterator over the borrowed [`Field`] items in this object. This /// iterator can be used to iterate over a named or unnamed struct or /// variant's fields uniformly. pubfn iter(&self) -> punctuated::Iter<Field> { matchself {
Fields::Unit => crate::punctuated::empty_punctuated_iter(),
Fields::Named(f) => f.named.iter(),
Fields::Unnamed(f) => f.unnamed.iter(),
}
}
/// Get an iterator over the mutably borrowed [`Field`] items in this /// object. This iterator can be used to iterate over a named or unnamed /// struct or variant's fields uniformly. pubfn iter_mut(&mutself) -> punctuated::IterMut<Field> { matchself {
Fields::Unit => crate::punctuated::empty_punctuated_iter_mut(),
Fields::Named(f) => f.named.iter_mut(),
Fields::Unnamed(f) => f.unnamed.iter_mut(),
}
}
/// Returns the number of fields. pubfn len(&self) -> usize { matchself {
Fields::Unit => 0,
Fields::Named(f) => f.named.len(),
Fields::Unnamed(f) => f.unnamed.len(),
}
}
/// Returns `true` if there are zero fields. pubfn is_empty(&self) -> bool { matchself {
Fields::Unit => true,
Fields::Named(f) => f.named.is_empty(),
Fields::Unnamed(f) => f.unnamed.is_empty(),
}
}
return_impl_trait! { /// Get an iterator over the fields of a struct or variant as [`Member`]s. /// This iterator can be used to iterate over a named or unnamed struct or /// variant's fields uniformly. /// /// # Example /// /// The following is a simplistic [`Clone`] derive for structs. (A more /// complete implementation would additionally want to infer trait bounds on /// the generic type parameters.) /// /// ``` /// # use quote::quote; /// # /// fn derive_clone(input: &syn::ItemStruct) -> proc_macro2::TokenStream { /// let ident = &input.ident; /// let members = input.fields.members(); /// let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); /// quote! { /// impl #impl_generics Clone for #ident #ty_generics #where_clause { /// fn clone(&self) -> Self { /// Self { /// #(#members: self.#members.clone()),* /// } /// } /// } /// } /// } /// ``` /// /// For structs with named fields, it produces an expression like `Self { a: /// self.a.clone() }`. For structs with unnamed fields, `Self { 0: /// self.0.clone() }`. And for unit structs, `Self {}`. pubfn members(&self) -> impl Iterator<Item = Member> + Clone + '_ [Members] {
Members {
fields: self.iter(),
index: 0,
}
}
}
}
impl IntoIterator for Fields { type Item = Field; type IntoIter = punctuated::IntoIter<Field>;
ast_struct! { /// A field of a struct or enum variant. #[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))] pubstruct Field { pub attrs: Vec<Attribute>,
pub vis: Visibility,
pub mutability: FieldMutability,
/// Name of the field, if any. /// /// Fields of tuple structs have no names. pub ident: Option<Ident>,
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.11Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.