aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-08-27 01:03:27 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-08-27 04:35:50 +0530
commit4ee5b664c2c8fde5175a7e3bfe2f1b1d77f6c5e1 (patch)
treedb03af6f2a58ec75c633fc6b75474578a48e83df /components/script/dom/bindings/codegen/CodegenRust.py
parent4678ec16bb7e3aa242f30d6a9d675d5aeaec7cf7 (diff)
downloadservo-4ee5b664c2c8fde5175a7e3bfe2f1b1d77f6c5e1.tar.gz
servo-4ee5b664c2c8fde5175a7e3bfe2f1b1d77f6c5e1.zip
Document InheritTypes
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index a88904df663..a4ac848a3f7 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -5773,12 +5773,17 @@ class GlobalGenRoots():
CGGeneric("use std::mem;\n\n")]
for descriptor in descriptors:
name = descriptor.name
- protos = [CGGeneric('pub trait %s : Sized {}\n' % (name + 'Base'))]
+ protos = [CGGeneric("""\
+/// Types which are derived from `%(name)s` and can be freely converted
+/// to `%(name)s`
+pub trait %(name)sBase : Sized {}\n""" % {'name': name})]
for proto in descriptor.prototypeChain:
protos += [CGGeneric('impl %s for %s {}\n' % (proto + 'Base',
descriptor.concreteType))]
- derived = [CGGeneric('pub trait %s : Sized { fn %s(&self) -> bool; }\n' %
- (name + 'Derived', 'is_' + name.lower()))]
+ derived = [CGGeneric("""\
+/// Types which `%(name)s` derives from
+pub trait %(name)sDerived : Sized { fn %(method)s(&self) -> bool; }\n""" %
+ {'name': name, 'method': 'is_' + name.lower()})]
for protoName in descriptor.prototypeChain[1:-1]:
protoDescriptor = config.getDescriptor(protoName)
delegate = string.Template("""\
@@ -5800,6 +5805,8 @@ impl ${selfName} for ${baseName} {
pub struct ${name}Cast;
impl ${name}Cast {
#[inline]
+ /// Downcast an instance of a base class of `${name}` to an instance of
+ /// `${name}`, if it internally is an instance of `${name}`
pub fn to_ref<'a, T: ${toBound}+Reflectable>(base: &'a T) -> Option<&'a ${name}> {
match base.${checkFn}() {
true => Some(unsafe { mem::transmute(base) }),
@@ -5827,6 +5834,7 @@ impl ${name}Cast {
}
#[inline]
+ /// Upcast an instance of a derived class of `${name}` to `${name}`
pub fn from_ref<'a, T: ${fromBound}+Reflectable>(derived: &'a T) -> &'a ${name} {
unsafe { mem::transmute(derived) }
}