Generalise RootedReference

It now becomes RootedReference<'root> and includes an associated type for
the return type of its 'r' method.

This removes the need for OptionalRootedReference.
This commit is contained in:
Anthony Ramine 2016-05-13 14:23:09 +02:00
parent 0b3ab875f4
commit 45c9aa7487
3 changed files with 32 additions and 49 deletions

View file

@ -36,7 +36,7 @@ use devtools_traits::CSSError;
use devtools_traits::WorkerId;
use dom::abstractworker::SharedRt;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::js::{JS, Root};
use dom::bindings::js::{JS, Root, RootedReference};
use dom::bindings::refcounted::{Trusted, TrustedPromise};
use dom::bindings::reflector::{Reflectable, Reflector};
use dom::bindings::str::{DOMString, USVString};
@ -553,9 +553,9 @@ impl<'a, T: JSTraceable + Reflectable> RootedVec<'a, JS<T>> {
}
}
impl<'a, T: JSTraceable + Reflectable> RootedVec<'a, JS<T>> {
/// Obtain a safe slice of references that can't outlive that RootedVec.
pub fn r(&self) -> &[&T] {
impl<'a, 'root, T: JSTraceable + Reflectable + 'root> RootedReference<'root> for RootedVec<'a, JS<T>> {
type Ref = &'root [&'root T];
fn r(&'root self) -> &'root [&'root T] {
unsafe { mem::transmute(&self[..]) }
}
}