From 93a39d8b2f63c433dcf9625e9e12a0fce9b27123 Mon Sep 17 00:00:00 2001 From: Casper Meijn Date: Wed, 24 Apr 2024 13:39:55 +0200 Subject: [PATCH] fix: Remove clone call when copy is implemented Clippy reports: warning: using `clone` on type `Timestamp` which implements the `Copy` trait --- prost-types/src/duration.rs | 2 +- prost-types/src/timestamp.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/prost-types/src/duration.rs b/prost-types/src/duration.rs index 600716933..da6af2a5f 100644 --- a/prost-types/src/duration.rs +++ b/prost-types/src/duration.rs @@ -105,7 +105,7 @@ impl TryFrom for time::Duration { impl fmt::Display for Duration { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut d = self.clone(); + let mut d = *self; d.normalize(); if self.seconds < 0 && self.nanos < 0 { write!(f, "-")?; diff --git a/prost-types/src/timestamp.rs b/prost-types/src/timestamp.rs index 216712a4b..b81335cd9 100644 --- a/prost-types/src/timestamp.rs +++ b/prost-types/src/timestamp.rs @@ -50,7 +50,7 @@ impl Timestamp { /// /// [1]: https://github.com/google/protobuf/blob/v3.3.2/src/google/protobuf/util/time_util.cc#L59-L77 pub fn try_normalize(mut self) -> Result { - let before = self.clone(); + let before = self; self.normalize(); // If the seconds value has changed, and is either i64::MIN or i64::MAX, then the timestamp // normalization overflowed. @@ -201,7 +201,7 @@ impl TryFrom for std::time::SystemTime { type Error = TimestampError; fn try_from(mut timestamp: Timestamp) -> Result { - let orig_timestamp = timestamp.clone(); + let orig_timestamp = timestamp; timestamp.normalize(); let system_time = if timestamp.seconds >= 0 { @@ -211,8 +211,7 @@ impl TryFrom for std::time::SystemTime { timestamp .seconds .checked_neg() - .ok_or_else(|| TimestampError::OutOfSystemRange(timestamp.clone()))? - as u64, + .ok_or(TimestampError::OutOfSystemRange(timestamp))? as u64, )) }; @@ -234,7 +233,7 @@ impl FromStr for Timestamp { impl fmt::Display for Timestamp { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - datetime::DateTime::from(self.clone()).fmt(f) + datetime::DateTime::from(*self).fmt(f) } } #[cfg(test)]