aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/root.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2019-03-10 18:37:14 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2019-03-11 16:25:39 +0100
commit4d527b20eef23422d52e8f097a98b9ae00723fc3 (patch)
tree04ad46594f64a218aa699ec1822a2980d018868a /components/script/dom/bindings/root.rs
parent1744a42dad62a4051ab56f109393850c8aafe961 (diff)
downloadservo-4d527b20eef23422d52e8f097a98b9ae00723fc3.tar.gz
servo-4d527b20eef23422d52e8f097a98b9ae00723fc3.zip
Simplify RootedReference and make it specifically about slicesIt's now called DomSlice<T>.
Diffstat (limited to 'components/script/dom/bindings/root.rs')
-rw-r--r--components/script/dom/bindings/root.rs29
1 files changed, 17 insertions, 12 deletions
diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs
index 86184af243d..940e0700b85 100644
--- a/components/script/dom/bindings/root.rs
+++ b/components/script/dom/bindings/root.rs
@@ -256,18 +256,23 @@ pub unsafe fn trace_roots(tracer: *mut JSTracer) {
});
}
-/// Get a reference out of a rooted value.
-pub trait RootedReference<'root> {
- /// The type of the reference.
- type Ref: 'root;
- /// Obtain a reference out of the rooted value.
- fn r(&'root self) -> Self::Ref;
-}
-
-impl<'root, T: JSTraceable + DomObject + 'root> RootedReference<'root> for [Dom<T>] {
- type Ref = &'root [&'root T];
- fn r(&'root self) -> &'root [&'root T] {
- unsafe { mem::transmute(self) }
+/// Get a slice of references to DOM objects.
+pub trait DomSlice<T>
+where
+ T: JSTraceable + DomObject,
+{
+ /// Returns the slice of `T` references.
+ fn r(&self) -> &[&T];
+}
+
+impl<T> DomSlice<T> for [Dom<T>]
+where
+ T: JSTraceable + DomObject,
+{
+ #[inline]
+ fn r(&self) -> &[&T] {
+ let _ = mem::transmute::<Dom<T>, &T>;
+ unsafe { &*(self as *const [Dom<T>] as *const [&T]) }
}
}