MCPcopy Create free account
hub / github.com/carllerche/assert-struct / root_field_name

Method root_field_name

assert-struct-macros/src/pattern/field.rs:215–229  ·  view source on GitHub ↗

Get the root field name from this operation For NamedField/UnnamedField, returns that name For Chained, recursively finds the first field access (skipping Deref operations)

(&self)

Source from the content-addressed store, hash-verified

213 /// For NamedField/UnnamedField, returns that name
214 /// For Chained, recursively finds the first field access (skipping Deref operations)
215 pub(crate) fn root_field_name(&self) -> FieldName {
216 match self {
217 FieldOperation::NamedField { name, .. } => FieldName::Ident(name.clone()),
218 FieldOperation::UnnamedField { index, .. } => FieldName::Index(*index),
219 FieldOperation::Chained { operations, .. } => {
220 // Find the first non-Deref operation and get its root field name
221 operations
222 .iter()
223 .find(|op| !matches!(op, FieldOperation::Deref { .. }))
224 .expect("Chained operation must have at least one non-Deref operation")
225 .root_field_name()
226 }
227 _ => panic!("Cannot extract root field name from {:?}", self),
228 }
229 }
230
231 /// Get operations after the root field access (tail operations)
232 /// For NamedField/UnnamedField alone, returns None (no additional operations)

Callers 4

expand_struct_assertionFunction · 0.80
generate_pattern_nodesFunction · 0.80
parse_comma_separatedMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected