pub struct EventTime(/* private fields */);Expand description
A moment on the input timeline, measured from the tree’s epoch.
A Duration, never an Instant: a recognizer that reads Instant::now()
cannot be driven by a simulated clock, and a test that cannot advance the
clock cannot test a long press, a fling or a double-tap window without
sleeping. Every deadline in the gesture layer is expressed as an
EventTime, and the tree’s one InputClock is the
only thing that produces one.
Implementations§
Source§impl EventTime
impl EventTime
Sourcepub const fn from_duration(d: Duration) -> Self
pub const fn from_duration(d: Duration) -> Self
A time this far after the epoch.
Sourcepub const fn from_millis(ms: u64) -> Self
pub const fn from_millis(ms: u64) -> Self
Milliseconds after the epoch. Convenience for tests and for backends whose timestamps arrive in milliseconds.
Sourcepub const fn as_duration(self) -> Duration
pub const fn as_duration(self) -> Duration
How far this is after the epoch.
Sourcepub const fn saturating_since(self, earlier: Self) -> Duration
pub const fn saturating_since(self, earlier: Self) -> Duration
How long after earlier this is, saturating at zero.
Saturating rather than panicking because samples can arrive out of order: a backend that batches coalesced moves may hand over a packet whose timestamps precede the last one already processed, and a gesture must degrade to “no time passed” rather than abort.
Sourcepub fn checked_add(self, d: Duration) -> Option<Self>
pub fn checked_add(self, d: Duration) -> Option<Self>
This time plus d, or None on overflow.
Deadlines are computed this way (now.checked_add(long_press)), so the
overflow case is real rather than theoretical for a caller that passes
Duration::MAX to mean “never”.
Trait Implementations§
Source§impl Add<Duration> for EventTime
impl Add<Duration> for EventTime
Source§fn add(self, d: Duration) -> Self
fn add(self, d: Duration) -> Self
now + d, saturating at Duration::MAX.
Saturating rather than panicking for the same reason
checked_add exists: Duration::MAX is a
legitimate way to say “never”, and a deadline arithmetic panic in the
middle of a gesture would be absurd. Reach for checked_add where the
overflow itself has to be observed.