1 | use std::ops::{Deref, DerefMut}; |
2 | |
3 | #[cfg (feature = "web-time" )] |
4 | use web_time::Instant; |
5 | |
6 | #[cfg (not(feature = "web-time" ))] |
7 | use std::time::Instant; |
8 | |
9 | use crate::event::Event; |
10 | |
11 | /// A debounced event is emitted after a short delay. |
12 | #[derive (Debug, Clone, PartialEq, Eq)] |
13 | pub struct DebouncedEvent { |
14 | /// The original event. |
15 | pub event: Event, |
16 | |
17 | /// The time at which the event occurred. |
18 | pub time: Instant, |
19 | } |
20 | |
21 | impl DebouncedEvent { |
22 | pub fn new(event: Event, time: Instant) -> Self { |
23 | Self { event, time } |
24 | } |
25 | } |
26 | |
27 | impl Deref for DebouncedEvent { |
28 | type Target = Event; |
29 | |
30 | fn deref(&self) -> &Self::Target { |
31 | &self.event |
32 | } |
33 | } |
34 | |
35 | impl DerefMut for DebouncedEvent { |
36 | fn deref_mut(&mut self) -> &mut Self::Target { |
37 | &mut self.event |
38 | } |
39 | } |
40 | |