@@ -28,12 +28,12 @@ impl Instant {
2828 self . 0 - other. 0
2929 }
3030
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) ? ) )
3333 }
3434
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) ? ) )
3737 }
3838}
3939
@@ -47,15 +47,11 @@ impl SystemTime {
4747 self . 0 . checked_sub ( other. 0 ) . ok_or_else ( || other. 0 - self . 0 )
4848 }
4949
50- pub fn add_duration ( & self , other : & Duration ) -> SystemTime {
51- SystemTime ( self . 0 + * other)
52- }
53-
5450 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) ? ) )
5652 }
5753
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) ? ) )
6056 }
6157}
0 commit comments