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
39
40
41
mod point;

use std::{
    fmt,
    ops::{Add, Deref},
};

pub use self::point::*;

/// A struct representing a location in time as milliseconds (i32)
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Millis(pub i32);

impl fmt::Display for Millis {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_fmt(format_args!("{}ms", self.0))
    }
}

impl From<i32> for Millis {
    fn from(v: i32) -> Self {
        Self(v)
    }
}

impl Deref for Millis {
    type Target = i32;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Add<Millis> for Millis {
    type Output = Millis;

    fn add(self, rhs: Millis) -> Self::Output {
        Millis(self.0 + rhs.0)
    }
}