@@ -28,12 +28,12 @@ impl Instant {
28
28
self . 0 - other. 0
29
29
}
30
30
31
- pub fn add_duration ( & self , other : & Duration ) -> Instant {
32
- Instant ( self . 0 + * other)
31
+ pub fn checked_add_duration ( & self , other : & Duration ) -> Option < Instant > {
32
+ Some ( Instant ( self . 0 . checked_add ( * other) ? ) )
33
33
}
34
34
35
- pub fn sub_duration ( & self , other : & Duration ) -> Instant {
36
- Instant ( self . 0 - * other)
35
+ pub fn checked_sub_duration ( & self , other : & Duration ) -> Option < Instant > {
36
+ Some ( Instant ( self . 0 . checked_sub ( * other) ? ) )
37
37
}
38
38
}
39
39
@@ -47,15 +47,11 @@ impl SystemTime {
47
47
self . 0 . checked_sub ( other. 0 ) . ok_or_else ( || other. 0 - self . 0 )
48
48
}
49
49
50
- pub fn add_duration ( & self , other : & Duration ) -> SystemTime {
51
- SystemTime ( self . 0 + * other)
52
- }
53
-
54
50
pub fn checked_add_duration ( & self , other : & Duration ) -> Option < SystemTime > {
55
- self . 0 . checked_add ( * other) . map ( |d| SystemTime ( d ) )
51
+ Some ( SystemTime ( self . 0 . checked_add ( * other) ? ) )
56
52
}
57
53
58
- pub fn sub_duration ( & self , other : & Duration ) -> SystemTime {
59
- SystemTime ( self . 0 - * other)
54
+ pub fn checked_sub_duration ( & self , other : & Duration ) -> Option < SystemTime > {
55
+ Some ( SystemTime ( self . 0 . checked_sub ( * other) ? ) )
60
56
}
61
57
}
0 commit comments