@@ -36,34 +36,23 @@ impl SystemTime {
3636 SystemTime ( Duration :: new ( now. seconds , now. nanoseconds ) )
3737 }
3838
39- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
40- pub const fn from_wasi_timestamp ( ts : wasi:: Timestamp ) -> SystemTime {
39+ pub fn from_wasi_timestamp ( ts : wasi:: Timestamp ) -> SystemTime {
4140 SystemTime ( Duration :: from_nanos ( ts) )
4241 }
4342
44- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
45- pub const fn to_wasi_timestamp ( & self ) -> Option < wasi:: Timestamp > {
46- // FIXME: const TryInto
47- let ns = self . 0 . as_nanos ( ) ;
48- if ns <= u64:: MAX as u128 { Some ( ns as u64 ) } else { None }
43+ pub fn to_wasi_timestamp ( & self ) -> Option < wasi:: Timestamp > {
44+ self . 0 . as_nanos ( ) . try_into ( ) . ok ( )
4945 }
5046
51- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
52- pub const fn sub_time ( & self , other : & SystemTime ) -> Result < Duration , Duration > {
53- // FIXME: ok_or_else with const closures
54- match self . 0 . checked_sub ( other. 0 ) {
55- Some ( duration) => Ok ( duration) ,
56- None => Err ( other. 0 - self . 0 ) ,
57- }
47+ pub fn sub_time ( & self , other : & SystemTime ) -> Result < Duration , Duration > {
48+ self . 0 . checked_sub ( other. 0 ) . ok_or_else ( || other. 0 - self . 0 )
5849 }
5950
60- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
61- pub const fn checked_add_duration ( & self , other : & Duration ) -> Option < SystemTime > {
51+ pub fn checked_add_duration ( & self , other : & Duration ) -> Option < SystemTime > {
6252 Some ( SystemTime ( self . 0 . checked_add ( * other) ?) )
6353 }
6454
65- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
66- pub const fn checked_sub_duration ( & self , other : & Duration ) -> Option < SystemTime > {
55+ pub fn checked_sub_duration ( & self , other : & Duration ) -> Option < SystemTime > {
6756 Some ( SystemTime ( self . 0 . checked_sub ( * other) ?) )
6857 }
6958}
0 commit comments