Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upIntroduce trait Castable #8041
Introduce trait Castable #8041
Conversation
highfive
commented
Oct 15, 2015
|
I got through the first two commits. Reviewed 3 of 3 files at r1, 1 of 1 files at r2. Comments from the review on Reviewable.io |
|
It's probably a good idea to always specify the type of downcasts; even if the compiler can technically infer the expected type, it's difficult to read. For example, in one case the type of a downcast is deduced based on the fact that LayoutHTMLInputElementHelpers is the only trait which currently has a method called "get_size_for_layout". |
|
@eefriedman I don't think so. The case you found maybe is surprising, but not much more than some Deref coercions we already have all over the place. In other occurrences, removing the type really helps readability: fn get_html_element(&self) -> Option<Root<HTMLHtmlElement>> {
self.GetDocumentElement().and_then(Root::downcast)
} |
|
|
|
|
|
|
|
|
|
|
|
Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. components/script/dom/bindings/conversions.rs, line 112 [r3] (raw file): components/script/dom/domimplementation.rs, line 118 [r4] (raw file): Comments from the review on Reviewable.io |
|
Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. components/script/dom/bindings/conversions.rs, line 112 [r3] (raw file): components/script/dom/domimplementation.rs, line 118 [r4] (raw file): let result = doc_node.AppendChild(doc_type.upcast());
assert!(result.is_ok());or expect. Comments from the review on Reviewable.io |
This method is given a DOMClass value and returns whether it derives from Self. Interfaces with no descendants directly check whether the given DOMClass is the same as their own.
This trait is used to hold onto the downcast and upcast functions of all
castable IDL interfaces. A castable IDL interface is one which either derives
from or is derived by other interfaces.
The deriving relation is represented by implementations of marker trait
DerivedFrom<T: Castable> generated in InheritTypes.
/^[ ]*use dom::bindings::codegen::InheritTypes::.*(Base|Cast|Derived)/ {
/::[a-zA-Z]+(Base|Cast|Derived);/d
s/([{ ])[a-zA-Z]+(Base|Cast|Derived), /\1/g
s/([{ ])[a-zA-Z]+(Base|Cast|Derived), /\1/g
s/, [a-zA-Z]+(Base|Cast|Derived)([},])/\2/g
s/, [a-zA-Z]+(Base|Cast|Derived)([},])/\2/g
/\{([a-zA-Z]+(Base|Cast|Derived))?\};$/d
s/\{([a-zA-Z_]+)\};$/\1;/
}
s/([a-zA-Z]+)Cast::from_ref\(\&?\**([a-zA-Z_]+)(\.r\(\))?\)/\2.upcast::<\1>()/g
s/([a-zA-Z]+)Cast::from_ref\(\&?\**([a-zA-Z_]+)(\.[a-zA-Z_]+\(\))?\)/\2\3.upcast::<\1>()/g
s/\(([a-zA-Z]+)Cast::from_ref\)/\(Castable::upcast::<\1>\)/g
s/([a-zA-Z]+)Cast::from_root/Root::upcast::<\1>/g
s/([a-zA-Z]+)Cast::from_layout_js\(\&([a-zA-Z_.]+)\)/\2.upcast::<\1>()/g
s/([a-zA-Z]+)Cast::to_ref\(\&?\**([a-zA-Z_]+)(\.r\(\))?\)/\2.downcast::<\1>()/g
s/([a-zA-Z]+)Cast::to_ref\(\&?\**([a-zA-Z_]+)(\.[a-zA-Z_]+\(\))?\)/\2\3.downcast::<\1>()/g
s/\(([a-zA-Z]+)Cast::to_ref\)/\(Castable::downcast::<\1>\)/g
s/([a-zA-Z]+)Cast::to_root/Root::downcast::<\1>/g
s/([a-zA-Z]+)Cast::to_layout_js\(&?([a-zA-Z_.]+(\(\))?)\)/\2.downcast::<\1>()/g
s/\.is_document\(\)/.is::<Document>()/g
s/\.is_htmlanchorelement\(\)/.is::<HTMLAnchorElement>()/g
s/\.is_htmlappletelement\(\)/.is::<HTMLAppletElement>()/g
s/\.is_htmlareaelement\(\)/.is::<HTMLAreaElement>()/g
s/\.is_htmlbodyelement\(\)/.is::<HTMLBodyElement>()/g
s/\.is_htmlembedelement\(\)/.is::<HTMLEmbedElement>()/g
s/\.is_htmlfieldsetelement\(\)/.is::<HTMLFieldSetElement>()/g
s/\.is_htmlformelement\(\)/.is::<HTMLFormElement>()/g
s/\.is_htmlframesetelement\(\)/.is::<HTMLFrameSetElement>()/g
s/\.is_htmlhtmlelement\(\)/.is::<HTMLHtmlElement>()/g
s/\.is_htmlimageelement\(\)/.is::<HTMLImageElement>()/g
s/\.is_htmllegendelement\(\)/.is::<HTMLLegendElement>()/g
s/\.is_htmloptgroupelement\(\)/.is::<HTMLOptGroupElement>()/g
s/\.is_htmloptionelement\(\)/.is::<HTMLOptionElement>()/g
s/\.is_htmlscriptelement\(\)/.is::<HTMLScriptElement>()/g
s/\.is_htmltabledatacellelement\(\)/.is::<HTMLTableDataCellElement>()/g
s/\.is_htmltableheadercellelement\(\)/.is::<HTMLTableHeaderCellElement>()/g
s/\.is_htmltablerowelement\(\)/.is::<HTMLTableRowElement>()/g
s/\.is_htmltablesectionelement\(\)/.is::<HTMLTableSectionElement>()/g
s/\.is_htmltitleelement\(\)/.is::<HTMLTitleElement>()/g
|
@jdm Rebased and addressed, I would appreciate it if I don't need to ever rebase that again. ;) |
|
Added a commit to fix #8125. |
|
@bors-servo: r+ Reviewed 35 of 35 files at r6. Comments from the review on Reviewable.io |
|
|
|
@bors-servo p=1 |
Introduce trait Castable Removes all those messy FooCast structures in InheritTypes.rs. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8041) <!-- Reviewable:end -->
|
|
nox commentedOct 15, 2015
Removes all those messy FooCast structures in InheritTypes.rs.