diff options
| author | bors <bors@rust-lang.org> | 2017-12-20 14:47:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-20 14:47:21 +0000 |
| commit | 81622c6b02536bdcf56145beb317da0d336703c1 (patch) | |
| tree | 2624499fcf70ff3d8f4072b6aab9a42b9ec9342a /src/libstd/sys | |
| parent | df8dfdeff68e60a68d026a3374cfb8159d0495cb (diff) | |
| parent | 66e5c790682204d35191dd62332c6f503cdeddbd (diff) | |
| download | rust-81622c6b02536bdcf56145beb317da0d336703c1.tar.gz rust-81622c6b02536bdcf56145beb317da0d336703c1.zip | |
Auto merge of #46874 - kennytm:rollup, r=kennytm
Rollup of 14 pull requests - Successful merges: #46359, #46517, #46671, #46751, #46760, #46787, #46794, #46828, #46831, #46835, #46851, #46852, #46856, #46870 - Failed merges:
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/redox/time.rs | 12 | ||||
| -rw-r--r-- | src/libstd/sys/unix/time.rs | 16 | ||||
| -rw-r--r-- | src/libstd/sys/wasm/time.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/windows/time.rs | 9 |
4 files changed, 32 insertions, 9 deletions
diff --git a/src/libstd/sys/redox/time.rs b/src/libstd/sys/redox/time.rs index 6c071afd42d..cf798500b7f 100644 --- a/src/libstd/sys/redox/time.rs +++ b/src/libstd/sys/redox/time.rs @@ -13,6 +13,7 @@ use fmt; use sys::{cvt, syscall}; use time::Duration; use convert::TryInto; +use core::hash::{Hash, Hasher}; const NSEC_PER_SEC: u64 = 1_000_000_000; @@ -110,12 +111,19 @@ impl Ord for Timespec { } } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +impl Hash for Timespec { + fn hash<H : Hasher>(&self, state: &mut H) { + self.t.tv_sec.hash(state); + self.t.tv_nsec.hash(state); + } +} + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Instant { t: Timespec, } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SystemTime { t: Timespec, } diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index 837cd7292e2..83127935909 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -11,6 +11,7 @@ use cmp::Ordering; use libc; use time::Duration; +use core::hash::{Hash, Hasher}; pub use self::inner::{Instant, SystemTime, UNIX_EPOCH}; use convert::TryInto; @@ -111,6 +112,13 @@ impl Ord for Timespec { } } +impl Hash for Timespec { + fn hash<H : Hasher>(&self, state: &mut H) { + self.t.tv_sec.hash(state); + self.t.tv_nsec.hash(state); + } +} + #[cfg(any(target_os = "macos", target_os = "ios"))] mod inner { use fmt; @@ -123,12 +131,12 @@ mod inner { use super::NSEC_PER_SEC; use super::Timespec; - #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct Instant { t: u64 } - #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SystemTime { t: Timespec, } @@ -255,12 +263,12 @@ mod inner { use super::Timespec; - #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Instant { t: Timespec, } - #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SystemTime { t: Timespec, } diff --git a/src/libstd/sys/wasm/time.rs b/src/libstd/sys/wasm/time.rs index 7907720e4da..c269def98f6 100644 --- a/src/libstd/sys/wasm/time.rs +++ b/src/libstd/sys/wasm/time.rs @@ -11,10 +11,10 @@ use fmt; use time::Duration; -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct Instant; -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SystemTime; pub const UNIX_EPOCH: SystemTime = SystemTime; diff --git a/src/libstd/sys/windows/time.rs b/src/libstd/sys/windows/time.rs index 1be29b5139a..07e64d386a1 100644 --- a/src/libstd/sys/windows/time.rs +++ b/src/libstd/sys/windows/time.rs @@ -17,11 +17,12 @@ use sys::cvt; use sys_common::mul_div_u64; use time::Duration; use convert::TryInto; +use core::hash::{Hash, Hasher}; const NANOS_PER_SEC: u64 = 1_000_000_000; const INTERVALS_PER_SEC: u64 = NANOS_PER_SEC / 100; -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)] pub struct Instant { t: c::LARGE_INTEGER, } @@ -173,6 +174,12 @@ impl From<c::FILETIME> for SystemTime { } } +impl Hash for SystemTime { + fn hash<H : Hasher>(&self, state: &mut H) { + self.intervals().hash(state) + } +} + fn dur2intervals(d: &Duration) -> i64 { d.as_secs() .checked_mul(INTERVALS_PER_SEC) |
