MCPcopy Index your code
hub / github.com/RustPython/RustPython / parse_fields

Function parse_fields

crates/derive-impl/src/pystructseq.rs:66–154  ·  view source on GitHub ↗

Parse field info from struct

(input: &mut DeriveInput)

Source from the content-addressed store, hash-verified

64
65/// Parse field info from struct
66fn parse_fields(input: &mut DeriveInput) -> Result<FieldInfo> {
67 let syn::Data::Struct(struc) = &mut input.data else {
68 bail_span!(input, "#[pystruct_sequence_data] can only be on a struct")
69 };
70
71 let syn::Fields::Named(fields) = &mut struc.fields else {
72 bail_span!(
73 input,
74 "#[pystruct_sequence_data] can only be on a struct with named fields"
75 );
76 };
77
78 let mut parsed_fields = Vec::with_capacity(fields.named.len());
79
80 for field in &mut fields.named {
81 let mut skip = false;
82 let mut unnamed = false;
83 let mut attrs_to_remove = Vec::new();
84 let mut cfg_attrs = Vec::new();
85
86 for (i, attr) in field.attrs.iter().enumerate() {
87 // Collect cfg attributes for conditional compilation
88 if attr.path().is_ident("cfg") {
89 cfg_attrs.push(attr.clone());
90 continue;
91 }
92
93 if !attr.path().is_ident("pystruct_sequence") {
94 continue;
95 }
96
97 let Ok(meta) = attr.parse_meta() else {
98 continue;
99 };
100
101 let Meta::List(l) = meta else {
102 bail_span!(input, "Only #[pystruct_sequence(...)] form is allowed");
103 };
104
105 let idents: Vec<_> = l
106 .nested
107 .iter()
108 .filter_map(|n| n.get_ident())
109 .cloned()
110 .collect();
111
112 for ident in idents {
113 match ident.to_string().as_str() {
114 "skip" => {
115 skip = true;
116 }
117 "unnamed" => {
118 unnamed = true;
119 }
120 _ => {
121 bail_span!(ident, "Unknown item for #[pystruct_sequence(...)]")
122 }
123 }

Callers 1

Calls 12

newFunction · 0.85
collectMethod · 0.80
to_stringMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
pathMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
as_strMethod · 0.45
cmpMethod · 0.45
removeMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected