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 crate::time::Instant;

/// A request to redraw a window.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum RedrawRequest {
    /// Redraw the next frame.
    NextFrame,

    /// Redraw at the given time.
    At(Instant),
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::time::Duration;

    #[test]
    fn ordering() {
        let now = Instant::now();
        let later = now + Duration::from_millis(10);

        assert_eq!(RedrawRequest::NextFrame, RedrawRequest::NextFrame);
        assert_eq!(RedrawRequest::At(now), RedrawRequest::At(now));

        assert!(RedrawRequest::NextFrame < RedrawRequest::At(now));
        assert!(RedrawRequest::At(now) > RedrawRequest::NextFrame);
        assert!(RedrawRequest::At(now) < RedrawRequest::At(later));
        assert!(RedrawRequest::At(later) > RedrawRequest::At(now));

        assert!(RedrawRequest::NextFrame <= RedrawRequest::NextFrame);
        assert!(RedrawRequest::NextFrame <= RedrawRequest::At(now));
        assert!(RedrawRequest::At(now) >= RedrawRequest::NextFrame);
        assert!(RedrawRequest::At(now) <= RedrawRequest::At(now));
        assert!(RedrawRequest::At(now) <= RedrawRequest::At(later));
        assert!(RedrawRequest::At(later) >= RedrawRequest::At(now));
    }
}