pub enum Fields {
Named(FieldsNamed),
Unnamed(FieldsUnnamed),
Unit,
}
full
or derive
only.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) -> impl Iterator<Item = Member> + Clone + '_
pub fn members(&self) -> impl Iterator<Item = Member> + Clone + '_
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
Available on crate feature printing
only.
impl ToTokens for Fields
printing
only.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
extra-traits
only.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§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
parsing
and printing
only.Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty.Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 56 bytes
Size for each variant:
Named
: 48 bytesUnnamed
: 48 bytesUnit
: 0 bytes