rustolio_utils/web_sys/
event.rs1use wasm_bindgen::prelude::*;
12
13use crate::error::FromCustomError;
14
15pub trait EventExt {
16 fn target_<T: JsCast>(&self) -> crate::Result<T>;
17 fn current_target_<T: JsCast>(&self) -> crate::Result<T>;
18}
19
20impl EventExt for web_sys::Event {
21 #[track_caller]
22 fn current_target_<T: JsCast>(&self) -> crate::Result<T> {
23 Ok(self
24 .current_target()
25 .context("Event does not have a `current_target`")?
26 .unchecked_into::<T>())
27 }
28 #[track_caller]
29 fn target_<T: JsCast>(&self) -> crate::Result<T> {
30 Ok(self
31 .target()
32 .context("Event does not have a `target`")?
33 .unchecked_into::<T>())
34 }
35}