From c50e987b4e169e2d7dc7089c91407e1e55c550f1 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sun, 10 Mar 2019 08:29:23 -0700 Subject: Add extra traits for all types Derive Clone, Copy, Eq, Hash, and PartialEq for all types. Not all traits are supported by all types, which is why many are missing some. --- src/sys/time.rs | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) (limited to 'src/sys/time.rs') diff --git a/src/sys/time.rs b/src/sys/time.rs index 4bd3b780..3ad57543 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -45,7 +45,7 @@ pub trait TimeValLike: Sized { } #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct TimeSpec(timespec); const NANOS_PER_SEC: i64 = 1_000_000_000; @@ -67,25 +67,6 @@ impl AsRef for TimeSpec { } } -impl fmt::Debug for TimeSpec { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_struct("TimeSpec") - .field("tv_sec", &self.tv_sec()) - .field("tv_nsec", &self.tv_nsec()) - .finish() - } -} - -impl PartialEq for TimeSpec { - // The implementation of cmp is simplified by assuming that the struct is - // normalized. That is, tv_nsec must always be within [0, 1_000_000_000) - fn eq(&self, other: &TimeSpec) -> bool { - self.tv_sec() == other.tv_sec() && self.tv_nsec() == other.tv_nsec() - } -} - -impl Eq for TimeSpec {} - impl Ord for TimeSpec { // The implementation of cmp is simplified by assuming that the struct is // normalized. That is, tv_nsec must always be within [0, 1_000_000_000) @@ -259,7 +240,7 @@ impl fmt::Display for TimeSpec { #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct TimeVal(timeval); const MICROS_PER_SEC: i64 = 1_000_000; @@ -278,25 +259,6 @@ impl AsRef for TimeVal { } } -impl fmt::Debug for TimeVal { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_struct("TimeVal") - .field("tv_sec", &self.tv_sec()) - .field("tv_usec", &self.tv_usec()) - .finish() - } -} - -impl PartialEq for TimeVal { - // The implementation of cmp is simplified by assuming that the struct is - // normalized. That is, tv_usec must always be within [0, 1_000_000) - fn eq(&self, other: &TimeVal) -> bool { - self.tv_sec() == other.tv_sec() && self.tv_usec() == other.tv_usec() - } -} - -impl Eq for TimeVal {} - impl Ord for TimeVal { // The implementation of cmp is simplified by assuming that the struct is // normalized. That is, tv_usec must always be within [0, 1_000_000) -- cgit v1.2.3