MCPcopy Create free account
hub / github.com/apache/fory / get_nested_field_attr

Method get_nested_field_attr

compiler/fory_compiler/generators/rust.py:1381–1407  ·  view source on GitHub ↗

Return nested list/map field configuration.

(self, field_type: FieldType)

Source from the content-addressed store, hash-verified

1379 return None
1380
1381 def get_nested_field_attr(self, field_type: FieldType) -> Optional[str]:
1382 """Return nested list/map field configuration."""
1383 if (
1384 isinstance(field_type, PrimitiveType)
1385 and field_type.kind == PrimitiveKind.BYTES
1386 ):
1387 return "bytes"
1388 if isinstance(field_type, ListType):
1389 element_attrs = self.get_nested_value_attrs(field_type.element_type)
1390 if element_attrs:
1391 return f"list(element({', '.join(element_attrs)}))"
1392 return None
1393 if isinstance(field_type, ArrayType):
1394 return "array"
1395 if isinstance(field_type, MapType):
1396 key_attrs = self.get_nested_value_attrs(field_type.key_type)
1397 value_attrs = self.get_nested_value_attrs(field_type.value_type)
1398 parts = []
1399 if key_attrs:
1400 parts.append(f"key({', '.join(key_attrs)})")
1401 if value_attrs or field_type.value_optional:
1402 if field_type.value_optional:
1403 value_attrs = ["nullable = true", *value_attrs]
1404 parts.append(f"value({', '.join(value_attrs)})")
1405 if parts:
1406 return f"map({', '.join(parts)})"
1407 return None
1408
1409 def get_payload_field_attr(self, field: Field) -> Optional[str]:
1410 """Return Rust derive metadata for a union payload field."""

Callers 3

generate_fieldMethod · 0.95

Calls 2

appendMethod · 0.45

Tested by

no test coverage detected