Skip to main content

scal_core/
seconds.rs

1/// Default type for time.
2pub type Time = f32;
3
4/// Allows for easy conversions of different number types into the time type(f32).
5/// Addition ally implements convenient functions for unit conversions- s ms
6pub trait DurationExt {
7    /// seconds
8    fn s(self) -> Time;
9    /// milliseconds
10    fn ms(self) -> Time;
11}
12
13impl DurationExt for f32 {
14    fn s(self) -> Time {
15        self
16    }
17    fn ms(self) -> Time {
18        self / 1000.0
19    }
20}
21
22#[allow(clippy::cast_precision_loss)]
23impl DurationExt for u32 {
24    fn s(self) -> Time {
25        self as f32
26    }
27    fn ms(self) -> Time {
28        self as f32 / 1000.0
29    }
30}
31
32#[allow(clippy::cast_precision_loss)]
33impl DurationExt for i32 {
34    fn s(self) -> Time {
35        self as f32
36    }
37    fn ms(self) -> Time {
38        self as f32 / 1000.0
39    }
40}
41
42#[allow(clippy::cast_precision_loss)]
43impl DurationExt for u64 {
44    fn s(self) -> Time {
45        self as f32
46    }
47    fn ms(self) -> Time {
48        self as f32 / 1000.0
49    }
50}