pub enum Fields {
Named(FieldsNamed),
Unnamed(FieldsUnnamed),
Unit,
}
Expand description
Variants§
Named(FieldsNamed)
Named fields of a struct or struct variant such as Point { x: f64, y: f64 }
.
Unnamed(FieldsUnnamed)
Unnamed fields of a tuple struct or tuple variant such as Some(T)
.
Unit
Unit struct or unit variant such as None
.
Implementations§
Source§impl Fields
impl Fields
Sourcepub fn iter(&self) -> Iter<'_, Field> ⓘ
pub fn iter(&self) -> Iter<'_, Field> ⓘ
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.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, Field> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, Field> ⓘ
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.
Sourcepub fn members(&self) -> Members<'_>
pub fn members(&self) -> Members<'_>
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.)
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 {}
.
Trait Implementations§
Source§impl From<FieldsNamed> for Fields
impl From<FieldsNamed> for Fields
Source§fn from(e: FieldsNamed) -> Fields
fn from(e: FieldsNamed) -> Fields
Source§impl From<FieldsUnnamed> for Fields
impl From<FieldsUnnamed> for Fields
Source§fn from(e: FieldsUnnamed) -> Fields
fn from(e: FieldsUnnamed) -> Fields
Source§impl<'a> IntoIterator for &'a Fields
impl<'a> IntoIterator for &'a Fields
Source§impl<'a> IntoIterator for &'a mut Fields
impl<'a> IntoIterator for &'a mut Fields
Source§impl IntoIterator for Fields
impl IntoIterator for Fields
Source§impl ToTokens for Fields
impl ToTokens for Fields
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,
Auto Trait Implementations§
impl Freeze for Fields
impl RefUnwindSafe for Fields
impl !Send for Fields
impl !Sync for Fields
impl Unpin for Fields
impl UnwindSafe for Fields
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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
Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty.