Make OpaqueLayoutAndStyleData just a bit less opaque

It now stores a NonNull<dyn Any>.
This commit is contained in:
Anthony Ramine 2020-04-02 13:17:44 +02:00
parent e47e884cc7
commit 4c61baee30
11 changed files with 83 additions and 65 deletions

View file

@ -8,17 +8,15 @@ use crate::data::StyleAndLayoutData;
use script_layout_interface::wrapper_traits::GetLayoutData;
pub trait GetRawData {
fn get_raw_data(&self) -> Option<&StyleAndLayoutData>;
unsafe fn get_raw_data(&self) -> Option<&StyleAndLayoutData>;
}
impl<'dom, T> GetRawData for T
where
T: GetLayoutData<'dom>,
{
fn get_raw_data(&self) -> Option<&StyleAndLayoutData> {
self.get_style_and_layout_data().map(|opaque| {
let container = opaque.ptr.as_ptr() as *mut StyleAndLayoutData;
unsafe { &*container }
})
unsafe fn get_raw_data(&self) -> Option<&StyleAndLayoutData> {
self.get_style_and_layout_data()
.map(|opaque| opaque.downcast_ref().unwrap())
}
}