diff options
| author | Vitaly _Vi Shukela <vi0oss@gmail.com> | 2017-12-19 00:35:43 +0300 |
|---|---|---|
| committer | Vitaly _Vi Shukela <vi0oss@gmail.com> | 2017-12-19 00:35:43 +0300 |
| commit | 1d5ead453dd96c1040a12cbb3b0180027af165c9 (patch) | |
| tree | 5df65995c6ae6eb6b136c717b5cc59e19a842d96 /src/libstd/sys | |
| parent | a3a7203e2c9ed30a501da86f3fa1f9efe707ac94 (diff) | |
| download | rust-1d5ead453dd96c1040a12cbb3b0180027af165c9.tar.gz rust-1d5ead453dd96c1040a12cbb3b0180027af165c9.zip | |
Add Hash impl for SystemTime and Instant
Closes #46670.
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) |
