downcast data with panic
This commit is contained in:
1 file changed
+7
-6
@@ -696,12 +696,13 @@ impl AttributeValue {
|
|||||||
/// The callback must be confined to the lifetime of the ScopeState
|
/// The callback must be confined to the lifetime of the ScopeState
|
||||||
pub fn listener<T: 'static>(mut callback: impl FnMut(Event<T>) + 'static) -> AttributeValue {
|
pub fn listener<T: 'static>(mut callback: impl FnMut(Event<T>) + 'static) -> AttributeValue {
|
||||||
AttributeValue::Listener(EventHandler::new(move |event: Event<dyn Any>| {
|
AttributeValue::Listener(EventHandler::new(move |event: Event<dyn Any>| {
|
||||||
if let Ok(data) = event.data.downcast::<T>() {
|
let data = event.data.downcast::<T>().unwrap();
|
||||||
callback(Event {
|
// if let Ok(data) = event.data.downcast::<T>() {
|
||||||
propagates: event.propagates,
|
callback(Event {
|
||||||
data,
|
propagates: event.propagates,
|
||||||
});
|
data,
|
||||||
}
|
});
|
||||||
|
// }
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user