libstd: convert `Duration` unops to by value

This commit is contained in:
Jorge Aparicio 2014-12-15 17:06:34 -05:00
parent 340f042e03
commit 5f347d7708
1 changed files with 14 additions and 0 deletions

View File

@ -265,6 +265,8 @@ impl Duration {
}
}
// NOTE(stage0): Remove impl after a snapshot
#[cfg(stage0)]
impl Neg<Duration> for Duration {
#[inline]
fn neg(&self) -> Duration {
@ -276,6 +278,18 @@ impl Neg<Duration> for Duration {
}
}
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
impl Neg<Duration> for Duration {
#[inline]
fn neg(self) -> Duration {
if self.nanos == 0 {
Duration { secs: -self.secs, nanos: 0 }
} else {
Duration { secs: -self.secs - 1, nanos: NANOS_PER_SEC - self.nanos }
}
}
}
// NOTE(stage0): Remove impl after a snapshot
#[cfg(stage0)]
impl Add<Duration,Duration> for Duration {