1
- use crate :: { NonMinI64 , TimeType } ;
2
-
3
- use super :: TimeInt ;
1
+ use crate :: { NonMinI64 , TimeInt , TimeType } ;
4
2
5
3
pub struct OutOfRange ;
6
4
5
+ /// An typed cell of an index, e.g. a point in time on some unknown timeline.
7
6
#[ derive( Copy , Clone , Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
8
7
#[ cfg_attr( feature = "serde" , derive( serde:: Deserialize , serde:: Serialize ) ) ]
9
- /// An typed cell of an index, e.g. a point in time on some unknown timeline.
10
8
pub struct IndexCell {
11
9
pub typ : TimeType ,
12
10
pub value : NonMinI64 ,
@@ -49,15 +47,13 @@ impl IndexCell {
49
47
self . typ
50
48
}
51
49
50
+ /// Internal encoding.
51
+ ///
52
+ /// Its meaning depends on the [`Self::typ`].
52
53
#[ inline]
53
54
pub fn as_i64 ( & self ) -> i64 {
54
55
self . value . into ( )
55
56
}
56
-
57
- #[ inline]
58
- pub fn as_time_int ( & self ) -> TimeInt {
59
- TimeInt :: from ( self . value )
60
- }
61
57
}
62
58
63
59
impl re_byte_size:: SizeBytes for IndexCell {
@@ -72,7 +68,29 @@ impl re_byte_size::SizeBytes for IndexCell {
72
68
}
73
69
}
74
70
71
+ impl From < IndexCell > for TimeInt {
72
+ #[ inline]
73
+ fn from ( cell : IndexCell ) -> Self {
74
+ Self :: from ( cell. value )
75
+ }
76
+ }
77
+
78
+ impl From < IndexCell > for NonMinI64 {
79
+ #[ inline]
80
+ fn from ( cell : IndexCell ) -> Self {
81
+ cell. value
82
+ }
83
+ }
84
+
85
+ impl From < IndexCell > for i64 {
86
+ #[ inline]
87
+ fn from ( cell : IndexCell ) -> Self {
88
+ cell. value . get ( )
89
+ }
90
+ }
91
+
75
92
impl From < std:: time:: Duration > for IndexCell {
93
+ /// Saturating cast from [`std::time::Duration`].
76
94
fn from ( time : std:: time:: Duration ) -> Self {
77
95
Self :: from_duration_nanos ( NonMinI64 :: saturating_from_u128 ( time. as_nanos ( ) ) )
78
96
}
@@ -99,7 +117,7 @@ impl TryFrom<web_time::SystemTime> for IndexCell {
99
117
100
118
fn try_from ( time : web_time:: SystemTime ) -> Result < Self , Self :: Error > {
101
119
let duration_since_epoch = time
102
- . duration_since ( std :: time :: SystemTime :: UNIX_EPOCH )
120
+ . duration_since ( web_time :: SystemTime :: UNIX_EPOCH )
103
121
. map_err ( |_ignored| OutOfRange ) ?;
104
122
let nanos_since_epoch = duration_since_epoch. as_nanos ( ) ;
105
123
let nanos_since_epoch = i64:: try_from ( nanos_since_epoch) . map_err ( |_ignored| OutOfRange ) ?;
0 commit comments