Skip to content

Commit

Permalink
introduce downcast to Element
Browse files Browse the repository at this point in the history
  • Loading branch information
derezzedex committed Feb 2, 2025
1 parent 599d8b5 commit 5fed200
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ impl<'a, Message, Theme, Renderer> Element<'a, Message, Theme, Renderer> {
widget: Box::new(Explain::new(self, color.into())),
}
}

/// TODO
pub fn downcast<T: Widget<Message, Theme, Renderer>>(self) -> Box<T>
where
Message: 'a,
Theme: 'a,
Renderer: crate::Renderer + 'a,
{
#[allow(unsafe_code)]
unsafe {
Box::from_raw(Box::into_raw(self.widget) as *mut T)
}
}
}

impl<'a, Message, Theme, Renderer>
Expand Down

0 comments on commit 5fed200

Please sign in to comment.