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,
impl Eq for Fields
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.