Skip to content

Commit 93a39d8

Browse files
committed
fix: Remove clone call when copy is implemented
Clippy reports: warning: using `clone` on type `Timestamp` which implements the `Copy` trait
1 parent 2ce0183 commit 93a39d8

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

prost-types/src/duration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl TryFrom<Duration> for time::Duration {
105105

106106
impl fmt::Display for Duration {
107107
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108-
let mut d = self.clone();
108+
let mut d = *self;
109109
d.normalize();
110110
if self.seconds < 0 && self.nanos < 0 {
111111
write!(f, "-")?;

prost-types/src/timestamp.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Timestamp {
5050
///
5151
/// [1]: https://github.com/google/protobuf/blob/v3.3.2/src/google/protobuf/util/time_util.cc#L59-L77
5252
pub fn try_normalize(mut self) -> Result<Timestamp, Timestamp> {
53-
let before = self.clone();
53+
let before = self;
5454
self.normalize();
5555
// If the seconds value has changed, and is either i64::MIN or i64::MAX, then the timestamp
5656
// normalization overflowed.
@@ -201,7 +201,7 @@ impl TryFrom<Timestamp> for std::time::SystemTime {
201201
type Error = TimestampError;
202202

203203
fn try_from(mut timestamp: Timestamp) -> Result<std::time::SystemTime, Self::Error> {
204-
let orig_timestamp = timestamp.clone();
204+
let orig_timestamp = timestamp;
205205
timestamp.normalize();
206206

207207
let system_time = if timestamp.seconds >= 0 {
@@ -211,8 +211,7 @@ impl TryFrom<Timestamp> for std::time::SystemTime {
211211
timestamp
212212
.seconds
213213
.checked_neg()
214-
.ok_or_else(|| TimestampError::OutOfSystemRange(timestamp.clone()))?
215-
as u64,
214+
.ok_or(TimestampError::OutOfSystemRange(timestamp))? as u64,
216215
))
217216
};
218217

@@ -234,7 +233,7 @@ impl FromStr for Timestamp {
234233

235234
impl fmt::Display for Timestamp {
236235
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
237-
datetime::DateTime::from(self.clone()).fmt(f)
236+
datetime::DateTime::from(*self).fmt(f)
238237
}
239238
}
240239
#[cfg(test)]

0 commit comments

Comments
 (0)