1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::ops::Sub;
use time_calc::Ticks;
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct Period<T = Ticks> {
pub start: T,
pub end: T,
}
impl<T> Period<T> {
pub fn duration(&self) -> T
where
T: Clone + Sub<T, Output = T>,
{
self.end.clone() - self.start.clone()
}
#[inline]
pub fn contains(&self, t: T) -> bool
where
T: PartialOrd + PartialEq,
{
t >= self.start && t < self.end
}
#[inline]
pub fn intersects(&self, other: &Self) -> bool
where
T: PartialOrd,
{
!(other.start > self.end || self.start > other.end)
}
}