about summary refs log tree commit diff
path: root/library/std/src/time.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/time.rs')
-rw-r--r--library/std/src/time.rs30
1 files changed, 21 insertions, 9 deletions
diff --git a/library/std/src/time.rs b/library/std/src/time.rs
index cd0683f44c9..07bb41f1496 100644
--- a/library/std/src/time.rs
+++ b/library/std/src/time.rs
@@ -551,8 +551,13 @@ impl SystemTime {
     /// println!("{difference:?}");
     /// ```
     #[stable(feature = "time2", since = "1.8.0")]
-    pub fn duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> {
-        self.0.sub_time(&earlier.0).map_err(SystemTimeError)
+    #[rustc_const_unstable(feature = "const_system_time", issue = "144517")]
+    pub const fn duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> {
+        // FIXME: map_err in const
+        match self.0.sub_time(&earlier.0) {
+            Ok(time) => Ok(time),
+            Err(err) => Err(SystemTimeError(err)),
+        }
     }
 
     /// Returns the difference from this system time to the
@@ -589,7 +594,8 @@ impl SystemTime {
     /// `SystemTime` (which means it's inside the bounds of the underlying data structure), `None`
     /// otherwise.
     #[stable(feature = "time_checked_add", since = "1.34.0")]
-    pub fn checked_add(&self, duration: Duration) -> Option<SystemTime> {
+    #[rustc_const_unstable(feature = "const_system_time", issue = "144517")]
+    pub const fn checked_add(&self, duration: Duration) -> Option<SystemTime> {
         self.0.checked_add_duration(&duration).map(SystemTime)
     }
 
@@ -597,13 +603,15 @@ impl SystemTime {
     /// `SystemTime` (which means it's inside the bounds of the underlying data structure), `None`
     /// otherwise.
     #[stable(feature = "time_checked_add", since = "1.34.0")]
-    pub fn checked_sub(&self, duration: Duration) -> Option<SystemTime> {
+    #[rustc_const_unstable(feature = "const_system_time", issue = "144517")]
+    pub const fn checked_sub(&self, duration: Duration) -> Option<SystemTime> {
         self.0.checked_sub_duration(&duration).map(SystemTime)
     }
 }
 
 #[stable(feature = "time2", since = "1.8.0")]
-impl Add<Duration> for SystemTime {
+#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
+impl const Add<Duration> for SystemTime {
     type Output = SystemTime;
 
     /// # Panics
@@ -616,14 +624,16 @@ impl Add<Duration> for SystemTime {
 }
 
 #[stable(feature = "time_augmented_assignment", since = "1.9.0")]
-impl AddAssign<Duration> for SystemTime {
+#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
+impl const AddAssign<Duration> for SystemTime {
     fn add_assign(&mut self, other: Duration) {
         *self = *self + other;
     }
 }
 
 #[stable(feature = "time2", since = "1.8.0")]
-impl Sub<Duration> for SystemTime {
+#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
+impl const Sub<Duration> for SystemTime {
     type Output = SystemTime;
 
     fn sub(self, dur: Duration) -> SystemTime {
@@ -632,7 +642,8 @@ impl Sub<Duration> for SystemTime {
 }
 
 #[stable(feature = "time_augmented_assignment", since = "1.9.0")]
-impl SubAssign<Duration> for SystemTime {
+#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
+impl const SubAssign<Duration> for SystemTime {
     fn sub_assign(&mut self, other: Duration) {
         *self = *self - other;
     }
@@ -699,7 +710,8 @@ impl SystemTimeError {
     /// ```
     #[must_use]
     #[stable(feature = "time2", since = "1.8.0")]
-    pub fn duration(&self) -> Duration {
+    #[rustc_const_unstable(feature = "const_system_time", issue = "144517")]
+    pub const fn duration(&self) -> Duration {
         self.0
     }
 }