Stabilize duration_checked_float
Tracking issue: - https://github.com/rust-lang/rust/issues/83400
This commit is contained in:
@@ -493,8 +493,8 @@ impl Error for crate::char::ParseCharError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "duration_checked_float", issue = "83400")]
|
#[stable(feature = "duration_checked_float", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl Error for crate::time::FromFloatSecsError {}
|
impl Error for crate::time::TryFromFloatSecsError {}
|
||||||
|
|
||||||
#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
|
#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
|
||||||
impl Error for crate::ffi::FromBytesWithNulError {
|
impl Error for crate::ffi::FromBytesWithNulError {
|
||||||
|
|||||||
@@ -1225,7 +1225,6 @@ impl fmt::Debug for Duration {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(duration_checked_float)]
|
|
||||||
/// use std::time::Duration;
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// if let Err(e) = Duration::try_from_secs_f32(-1.0) {
|
/// if let Err(e) = Duration::try_from_secs_f32(-1.0) {
|
||||||
@@ -1233,33 +1232,33 @@ impl fmt::Debug for Duration {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[unstable(feature = "duration_checked_float", issue = "83400")]
|
#[stable(feature = "duration_checked_float", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub struct FromFloatSecsError {
|
pub struct TryFromFloatSecsError {
|
||||||
kind: FromFloatSecsErrorKind,
|
kind: TryFromFloatSecsErrorKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromFloatSecsError {
|
impl TryFromFloatSecsError {
|
||||||
const fn description(&self) -> &'static str {
|
const fn description(&self) -> &'static str {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
FromFloatSecsErrorKind::Negative => {
|
TryFromFloatSecsErrorKind::Negative => {
|
||||||
"can not convert float seconds to Duration: value is negative"
|
"can not convert float seconds to Duration: value is negative"
|
||||||
}
|
}
|
||||||
FromFloatSecsErrorKind::OverflowOrNan => {
|
TryFromFloatSecsErrorKind::OverflowOrNan => {
|
||||||
"can not convert float seconds to Duration: value is either too big or NaN"
|
"can not convert float seconds to Duration: value is either too big or NaN"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "duration_checked_float", issue = "83400")]
|
#[stable(feature = "duration_checked_float", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl fmt::Display for FromFloatSecsError {
|
impl fmt::Display for TryFromFloatSecsError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
self.description().fmt(f)
|
self.description().fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
enum FromFloatSecsErrorKind {
|
enum TryFromFloatSecsErrorKind {
|
||||||
// Value is negative.
|
// Value is negative.
|
||||||
Negative,
|
Negative,
|
||||||
// Value is either too big to be represented as `Duration` or `NaN`.
|
// Value is either too big to be represented as `Duration` or `NaN`.
|
||||||
@@ -1280,7 +1279,7 @@ macro_rules! try_from_secs {
|
|||||||
const EXP_MASK: $bits_ty = (1 << $exp_bits) - 1;
|
const EXP_MASK: $bits_ty = (1 << $exp_bits) - 1;
|
||||||
|
|
||||||
if $secs < 0.0 {
|
if $secs < 0.0 {
|
||||||
return Err(FromFloatSecsError { kind: FromFloatSecsErrorKind::Negative });
|
return Err(TryFromFloatSecsError { kind: TryFromFloatSecsErrorKind::Negative });
|
||||||
}
|
}
|
||||||
|
|
||||||
let bits = $secs.to_bits();
|
let bits = $secs.to_bits();
|
||||||
@@ -1339,7 +1338,7 @@ macro_rules! try_from_secs {
|
|||||||
let secs = u64::from(mant) << (exp - $mant_bits);
|
let secs = u64::from(mant) << (exp - $mant_bits);
|
||||||
(secs, 0)
|
(secs, 0)
|
||||||
} else {
|
} else {
|
||||||
return Err(FromFloatSecsError { kind: FromFloatSecsErrorKind::OverflowOrNan });
|
return Err(TryFromFloatSecsError { kind: TryFromFloatSecsErrorKind::OverflowOrNan });
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Duration::new(secs, nanos))
|
Ok(Duration::new(secs, nanos))
|
||||||
@@ -1355,8 +1354,6 @@ impl Duration {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(duration_checked_float)]
|
|
||||||
///
|
|
||||||
/// use std::time::Duration;
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// let res = Duration::try_from_secs_f32(0.0);
|
/// let res = Duration::try_from_secs_f32(0.0);
|
||||||
@@ -1404,9 +1401,10 @@ impl Duration {
|
|||||||
/// let res = Duration::try_from_secs_f32(val);
|
/// let res = Duration::try_from_secs_f32(val);
|
||||||
/// assert_eq!(res, Ok(Duration::new(1, 2_929_688)));
|
/// assert_eq!(res, Ok(Duration::new(1, 2_929_688)));
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "duration_checked_float", issue = "83400")]
|
#[stable(feature = "duration_checked_float", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn try_from_secs_f32(secs: f32) -> Result<Duration, FromFloatSecsError> {
|
pub const fn try_from_secs_f32(secs: f32) -> Result<Duration, TryFromFloatSecsError> {
|
||||||
try_from_secs!(
|
try_from_secs!(
|
||||||
secs = secs,
|
secs = secs,
|
||||||
mantissa_bits = 23,
|
mantissa_bits = 23,
|
||||||
@@ -1425,8 +1423,6 @@ impl Duration {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(duration_checked_float)]
|
|
||||||
///
|
|
||||||
/// use std::time::Duration;
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// let res = Duration::try_from_secs_f64(0.0);
|
/// let res = Duration::try_from_secs_f64(0.0);
|
||||||
@@ -1482,9 +1478,10 @@ impl Duration {
|
|||||||
/// let res = Duration::try_from_secs_f64(val);
|
/// let res = Duration::try_from_secs_f64(val);
|
||||||
/// assert_eq!(res, Ok(Duration::new(1, 2_929_688)));
|
/// assert_eq!(res, Ok(Duration::new(1, 2_929_688)));
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "duration_checked_float", issue = "83400")]
|
#[stable(feature = "duration_checked_float", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn try_from_secs_f64(secs: f64) -> Result<Duration, FromFloatSecsError> {
|
pub const fn try_from_secs_f64(secs: f64) -> Result<Duration, TryFromFloatSecsError> {
|
||||||
try_from_secs!(
|
try_from_secs!(
|
||||||
secs = secs,
|
secs = secs,
|
||||||
mantissa_bits = 52,
|
mantissa_bits = 52,
|
||||||
|
|||||||
@@ -103,7 +103,6 @@
|
|||||||
#![feature(provide_any)]
|
#![feature(provide_any)]
|
||||||
#![feature(utf8_chunks)]
|
#![feature(utf8_chunks)]
|
||||||
#![feature(is_ascii_octdigit)]
|
#![feature(is_ascii_octdigit)]
|
||||||
#![feature(duration_checked_float)]
|
|
||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![deny(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|||||||
@@ -280,7 +280,6 @@
|
|||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
#![feature(cstr_from_bytes_until_nul)]
|
#![feature(cstr_from_bytes_until_nul)]
|
||||||
#![feature(cstr_internals)]
|
#![feature(cstr_internals)]
|
||||||
#![feature(duration_checked_float)]
|
|
||||||
#![feature(duration_constants)]
|
#![feature(duration_constants)]
|
||||||
#![feature(error_generic_member_access)]
|
#![feature(error_generic_member_access)]
|
||||||
#![feature(error_in_core)]
|
#![feature(error_in_core)]
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ use crate::sys_common::{FromInner, IntoInner};
|
|||||||
#[stable(feature = "time", since = "1.3.0")]
|
#[stable(feature = "time", since = "1.3.0")]
|
||||||
pub use core::time::Duration;
|
pub use core::time::Duration;
|
||||||
|
|
||||||
#[unstable(feature = "duration_checked_float", issue = "83400")]
|
#[stable(feature = "duration_checked_float", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub use core::time::FromFloatSecsError;
|
pub use core::time::TryFromFloatSecsError;
|
||||||
|
|
||||||
/// A measurement of a monotonically nondecreasing clock.
|
/// A measurement of a monotonically nondecreasing clock.
|
||||||
/// Opaque and useful only with [`Duration`].
|
/// Opaque and useful only with [`Duration`].
|
||||||
|
|||||||
Reference in New Issue
Block a user