On 03/04/2014 06:09 PM, Robert O'Callahan wrote:
On Wed, Mar 5, 2014 at 11:33 AM, Josh Matthews <j...@joshmatthews.net>wrote:

I know that some contributors have expressed confusion about the new JS<T>
types that are all over the DOM. I've started a guide to try and clear up
how to use them; please feel free to suggest further topics or make edits
yourself: https://github.com/mozilla/servo/wiki/JS-smart-pointers



let base: JS<Node> = NodeCast::from(element);if base.get().type_id()
== ElementNodeTypeId(HTMLTitleElementTypeId) {
   let derived: JS<HTMLTitleElement> = HTMLTitleElementCast::to(element);}

Can this not be simplified to something like
   let derived = HTMLTitleElement::checkedCast(element);
returning an Option<JS<HTMLTitleElement>>? Less verbose and less
error-prone that the instanceof/downcast pattern.

Rob


It can be, but there are cases when that would be wasted effort. I'm open either way.
_______________________________________________
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo

Reply via email to