add extension to downcast web events

This commit is contained in:
Evan Almloff committed 2023-08-28 17:16:56 -05:00
1 parent 8ba1c05a93
commit 097eb2099c
4 files changed
+442 -288

No files matched your search

+12
View File
@@ -10,6 +10,18 @@ pub struct PointerData {
inner: Box<dyn HasPointerData>,
}
impl PointerData {
/// Create a new PointerData
pub fn new(data: impl HasPointerData + 'static) -> Self {
Self::from(data)
}
/// Downcast this event to a concrete event type
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
}
impl<E: HasPointerData> From<E> for PointerData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }