diff options
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 7c6b2fe3718..4ea45ef9ded 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -1984,15 +1984,15 @@ def DOMClassTypeId(desc): inner = "" if desc.hasDescendants(): if desc.interface.getExtendedAttribute("Abstract"): - return "::dom::bindings::codegen::InheritTypes::TopTypeId::Abstract" + return "::dom::bindings::codegen::InheritTypes::TopTypeId { abstract_: () }" name = desc.interface.identifier.name inner = "(::dom::bindings::codegen::InheritTypes::%sTypeId::%s)" % (name, name) elif len(protochain) == 1: - return "::dom::bindings::codegen::InheritTypes::TopTypeId::Alone" + return "::dom::bindings::codegen::InheritTypes::TopTypeId { alone: () }" reversed_protochain = list(reversed(protochain)) for (child, parent) in zip(reversed_protochain, reversed_protochain[1:]): inner = "(::dom::bindings::codegen::InheritTypes::%sTypeId::%s%s)" % (parent, child, inner) - return "::dom::bindings::codegen::InheritTypes::TopTypeId::%s%s" % (protochain[0], inner) + return "::dom::bindings::codegen::InheritTypes::TopTypeId { %s: %s }" % (protochain[0].lower(), inner) def DOMClass(descriptor): @@ -6931,18 +6931,26 @@ class GlobalGenRoots(): typeIdCode = [] topTypeVariants = [ - ("ID used by abstract interfaces.", "Abstract"), - ("ID used by interfaces that are not castable.", "Alone"), + ("ID used by abstract interfaces.", "pub abstract_: ()"), + ("ID used by interfaces that are not castable.", "pub alone: ()"), ] topTypeVariants += [ - ("ID used by interfaces that derive from %s." % typeName, "%s(%sTypeId)" % (typeName, typeName)) + ("ID used by interfaces that derive from %s." % typeName, + "pub %s: %sTypeId" % (typeName.lower(), typeName)) for typeName in topTypes ] topTypeVariantsAsStrings = [CGGeneric("/// %s\n%s," % variant) for variant in topTypeVariants] typeIdCode.append(CGWrapper(CGIndenter(CGList(topTypeVariantsAsStrings, "\n"), 4), - pre="#[derive(Clone, Copy, Debug)]\npub enum TopTypeId {\n", + pre="#[derive(Copy)]\npub union TopTypeId {\n", post="\n}\n\n")) + typeIdCode.append(CGGeneric("""\ +impl Clone for TopTypeId { + fn clone(&self) -> Self { *self } +} + +""")) + def type_id_variant(name): # If `name` is present in the hierarchy keys', that means some other interfaces # derive from it and this enum variant should have an argument with its own @@ -6962,17 +6970,16 @@ class GlobalGenRoots(): typeIdCode.append(CGGeneric("""\ impl %(base)s { pub fn type_id(&self) -> &'static %(base)sTypeId { - let domclass = unsafe { - get_dom_class(self.reflector().get_jsobject().get()).unwrap() - }; - match domclass.type_id { - TopTypeId::%(base)s(ref type_id) => type_id, - _ => unreachable!(), + unsafe { + &get_dom_class(self.reflector().get_jsobject().get()) + .unwrap() + .type_id + .%(field)s } } } -""" % {'base': base})) +""" % {'base': base, 'field': base.lower()})) curr = CGList(imports + typeIdCode + allprotos) curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT) |