1
Fork 0

std: Stabilize APIs for the 1.8 release

This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:

Stabilized

* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`

Deprecated

* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`

Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
This commit is contained in:
Alex Crichton 2016-02-25 15:52:29 -08:00
parent 504ca6f422
commit b643782a10
52 changed files with 203 additions and 227 deletions

View file

@ -41,7 +41,7 @@ mod duration;
/// allows measuring the duration between two instants (or comparing two
/// instants).
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
pub struct Instant(time::Instant);
/// A measurement of the system clock, useful for talking to
@ -64,18 +64,18 @@ pub struct Instant(time::Instant);
/// fixed point in time, a `SystemTime` can be converted to a human-readable time,
/// or perhaps some other string representation.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
pub struct SystemTime(time::SystemTime);
/// An error returned from the `duration_from_earlier` method on `SystemTime`,
/// An error returned from the `duration_since` method on `SystemTime`,
/// used to learn about why how far in the opposite direction a timestamp lies.
#[derive(Clone, Debug)]
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
pub struct SystemTimeError(Duration);
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
impl Instant {
/// Returns an instant corresponding to "now".
#[stable(feature = "time2", since = "1.8.0")]
pub fn now() -> Instant {
Instant(time::Instant::now())
}
@ -88,6 +88,14 @@ impl Instant {
/// only be possible if `earlier` was created after `self`. Because
/// `Instant` is monotonic, the only time that this should happen should be
/// a bug.
#[stable(feature = "time2", since = "1.8.0")]
pub fn duration_since(&self, earlier: Instant) -> Duration {
self.0.sub_instant(&earlier.0)
}
/// Deprecated, renamed to `duration_since`
#[unstable(feature = "time2_old", issue = "29866")]
#[rustc_deprecated(since = "1.8.0", reason = "renamed to duration_since")]
pub fn duration_from_earlier(&self, earlier: Instant) -> Duration {
self.0.sub_instant(&earlier.0)
}
@ -99,12 +107,13 @@ impl Instant {
/// This function may panic if the current time is earlier than this
/// instant, which is something that can happen if an `Instant` is
/// produced synthetically.
#[stable(feature = "time2", since = "1.8.0")]
pub fn elapsed(&self) -> Duration {
Instant::now().duration_from_earlier(*self)
Instant::now() - *self
}
}
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
impl Add<Duration> for Instant {
type Output = Instant;
@ -113,7 +122,7 @@ impl Add<Duration> for Instant {
}
}
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
impl Sub<Duration> for Instant {
type Output = Instant;
@ -122,16 +131,25 @@ impl Sub<Duration> for Instant {
}
}
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
impl Sub<Instant> for Instant {
type Output = Duration;
fn sub(self, other: Instant) -> Duration {
self.duration_since(other)
}
}
#[stable(feature = "time2", since = "1.8.0")]
impl fmt::Debug for Instant {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
impl SystemTime {
/// Returns the system time corresponding to "now".
#[stable(feature = "time2", since = "1.8.0")]
pub fn now() -> SystemTime {
SystemTime(time::SystemTime::now())
}
@ -147,6 +165,15 @@ impl SystemTime {
///
/// Returns an `Err` if `earlier` is later than `self`, and the error
/// contains how far from `self` the time is.
#[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)
}
/// Deprecated, renamed to `duration_since`
#[unstable(feature = "time2_old", issue = "29866")]
#[rustc_deprecated(since = "1.8.0", reason = "renamed to duration_since")]
pub fn duration_from_earlier(&self, earlier: SystemTime)
-> Result<Duration, SystemTimeError> {
self.0.sub_time(&earlier.0).map_err(SystemTimeError)
@ -162,12 +189,13 @@ impl SystemTime {
///
/// Returns an `Err` if `self` is later than the current system time, and
/// the error contains how far from the current system time `self` is.
#[stable(feature = "time2", since = "1.8.0")]
pub fn elapsed(&self) -> Result<Duration, SystemTimeError> {
SystemTime::now().duration_from_earlier(*self)
SystemTime::now().duration_since(*self)
}
}
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
impl Add<Duration> for SystemTime {
type Output = SystemTime;
@ -176,7 +204,7 @@ impl Add<Duration> for SystemTime {
}
}
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
impl Sub<Duration> for SystemTime {
type Output = SystemTime;
@ -185,7 +213,7 @@ impl Sub<Duration> for SystemTime {
}
}
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
impl fmt::Debug for SystemTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
@ -196,32 +224,32 @@ impl fmt::Debug for SystemTime {
/// learn about where in time a `SystemTime` lies.
///
/// This constant is defined to be "1970-01-01 00:00:00 UTC" on all systems with
/// respect to the system clock. Using `duration_from_earlier` on an existing
/// respect to the system clock. Using `duration_since` on an existing
/// `SystemTime` instance can tell how far away from this point in time a
/// measurement lies, and using `UNIX_EPOCH + duration` can be used to create a
/// `SystemTime` instance to represent another fixed point in time.
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
pub const UNIX_EPOCH: SystemTime = SystemTime(time::UNIX_EPOCH);
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
impl SystemTimeError {
/// Returns the positive duration which represents how far forward the
/// second system time was from the first.
///
/// A `SystemTimeError` is returned from the `duration_from_earlier`
/// A `SystemTimeError` is returned from the `duration_since`
/// operation whenever the second system time represents a point later
/// in time than the `self` of the method call.
#[stable(feature = "time2", since = "1.8.0")]
pub fn duration(&self) -> Duration {
self.0
}
}
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
impl Error for SystemTimeError {
fn description(&self) -> &str { "other time was not earlier than self" }
}
#[unstable(feature = "time2", reason = "recently added", issue = "29866")]
#[stable(feature = "time2", since = "1.8.0")]
impl fmt::Display for SystemTimeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "second time provided was later than self")
@ -265,7 +293,7 @@ mod tests {
fn instant_math() {
let a = Instant::now();
let b = Instant::now();
let dur = b.duration_from_earlier(a);
let dur = b.duration_since(a);
assert_almost_eq!(b - dur, a);
assert_almost_eq!(a + dur, b);
@ -277,14 +305,14 @@ mod tests {
#[should_panic]
fn instant_duration_panic() {
let a = Instant::now();
(a - Duration::new(1, 0)).duration_from_earlier(a);
(a - Duration::new(1, 0)).duration_since(a);
}
#[test]
fn system_time_math() {
let a = SystemTime::now();
let b = SystemTime::now();
match b.duration_from_earlier(a) {
match b.duration_since(a) {
Ok(dur) if dur == Duration::new(0, 0) => {
assert_almost_eq!(a, b);
}
@ -302,8 +330,8 @@ mod tests {
}
let second = Duration::new(1, 0);
assert_almost_eq!(a.duration_from_earlier(a - second).unwrap(), second);
assert_almost_eq!(a.duration_from_earlier(a + second).unwrap_err()
assert_almost_eq!(a.duration_since(a - second).unwrap(), second);
assert_almost_eq!(a.duration_since(a + second).unwrap_err()
.duration(), second);
assert_almost_eq!(a - second + second, a);
@ -327,8 +355,8 @@ mod tests {
#[test]
fn since_epoch() {
let ts = SystemTime::now();
let a = ts.duration_from_earlier(UNIX_EPOCH).unwrap();
let b = ts.duration_from_earlier(UNIX_EPOCH - Duration::new(1, 0)).unwrap();
let a = ts.duration_since(UNIX_EPOCH).unwrap();
let b = ts.duration_since(UNIX_EPOCH - Duration::new(1, 0)).unwrap();
assert!(b > a);
assert_eq!(b - a, Duration::new(1, 0));