diff options
author | bors-servo <servo-ops@mozilla.com> | 2020-04-01 12:05:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-01 12:05:16 -0400 |
commit | af1ebe79efd799498010f196983a233aa5203d64 (patch) | |
tree | b58ec0d2bb328dee14f612b753dfdb5d375c3fdd /components/script/dom/bindings | |
parent | 59265775346cbab86467bea7e52b1922c1a31a11 (diff) | |
parent | 4e64a1c682183a5f982f9b6b9cbc6d99b4a3b6ba (diff) | |
download | servo-af1ebe79efd799498010f196983a233aa5203d64.tar.gz servo-af1ebe79efd799498010f196983a233aa5203d64.zip |
Auto merge of #26083 - servo:layout-2020-more-cleanups, r=jdm
More layout cleanups from the introduction of a lifetime in LayoutDom<T>
What can I say, the follow-up fixes just kept coming to my door one by one, I couldn't just tell them to go away.
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/root.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index 9afb421abbb..4f4d376e951 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -441,6 +441,15 @@ where debug_assert!(thread_state::get().is_layout()); self.value.downcast::<U>().map(|value| LayoutDom { value }) } + + /// Returns whether this inner object is a U. + pub fn is<U>(&self) -> bool + where + U: DerivedFrom<T>, + { + debug_assert!(thread_state::get().is_layout()); + self.value.is::<U>() + } } impl<T> LayoutDom<'_, T> @@ -736,6 +745,15 @@ where debug_assert!(thread_state::get().is_layout()); self.value } + + /// Transforms a slice of Dom<T> into a slice of LayoutDom<T>. + // FIXME(nox): This should probably be done through a ToLayout trait. + pub unsafe fn to_layout_slice(slice: &'dom [Dom<T>]) -> &'dom [LayoutDom<'dom, T>] { + // This doesn't compile if Dom and LayoutDom don't have the same + // representation. + let _ = mem::transmute::<Dom<T>, LayoutDom<T>>; + &*(slice as *const [Dom<T>] as *const [LayoutDom<T>]) + } } /// Helper trait for safer manipulations of `Option<Heap<T>>` values. |