Truly independent web browser
Meta: Name Rust unions after the typedefs of their member unions
Shannon Booth76fbfb31282b
diff --git a/Meta/Generators/libweb_bindings/rust_types.py b/Meta/Generators/libweb_bindings/rust_types.pyindex 97f619869fe..ace99ea70d2 100644--- a/Meta/Generators/libweb_bindings/rust_types.py+++ b/Meta/Generators/libweb_bindings/rust_types.py@@ -244,18 +244,23 @@ def is_unnamed_union_of_cpp_interfaces(idl_type: IDLType, context: GenerationCon)-def idl_type_name(idl_type: IDLType, what: str) -> str:+def idl_type_name(idl_type: IDLType, what: str, context: Optional[GenerationContext] = None) -> str:"""The name the Rust bindings give the type: Path2DOrDOMString for (Path2D or DOMString),- UnrestrictedDoubleSequence for sequence<unrestricted double>."""+ UnrestrictedDoubleSequence for sequence<unrestricted double>. Given the context, a member union that one typedef+ names has the typedef's name: DocumentOrXMLHttpRequestBodyInit for (Document or XMLHttpRequestBodyInit)."""if isinstance(idl_type, IDLUnionType):- name = "Or".join(idl_type_name(member_type, what) for member_type in idl_type.member_types)+ if context is not None:+ names = union_typedef_names(idl_type, context)+ if len(names) == 1:+ return f"{names[0]}OrNull" if idl_type.nullable else names[0]+ name = "Or".join(idl_type_name(member_type, what, context) for member_type in idl_type.member_types)elif isinstance(idl_type, IDLParameterizedType) and idl_type.name == "record":key_type, value_type = idl_type.parameters- name = f"{idl_type_name(key_type, what)}{idl_type_name(value_type, what)}Record"+ name = f"{idl_type_name(key_type, what, context)}{idl_type_name(value_type, what, context)}Record"elif isinstance(idl_type, IDLParameterizedType):if idl_type.name != "sequence":raise UnsupportedByRustBindings(f"{what} has the type {idl_type}, which the Rust bindings have no name for")- name = f"{idl_type_name(idl_type.parameters[0], what)}Sequence"+ name = f"{idl_type_name(idl_type.parameters[0], what, context)}Sequence"else:name = "".join(word[:1].upper() + word[1:] for word in idl_type.name.split(" "))return f"{name}OrNull" if idl_type.nullable else name@@ -391,7 +396,7 @@ def rust_union_path(idl_type: IDLUnionType, context: GenerationContext, what: stif len(names) > 1:raise UnsupportedByRustBindings(f"{what} has the union type {idl_type}, which the typedefs {names} all name")if not names:- type_name = idl_type_name(idl_type.without_nullable(), what)+ type_name = idl_type_name(idl_type.without_nullable(), what, context)if type_name in SHARED_UNNAMED_UNIONS:return f"{SHARED_UNNAMED_UNIONS[type_name]}::{type_name}"idl_path = unnamed_union_idl_path(idl_type, context, what)