Skip to content

Commit 4ca89a0

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 4ca89a0

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

prost-types/src/datetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ mod tests {
614614
};
615615
assert_eq!(
616616
expected,
617-
format!("{}", DateTime::from(timestamp.clone())),
617+
format!("{}", DateTime::from(timestamp)),
618618
"timestamp: {:?}",
619619
timestamp
620620
);

prost-types/src/duration.rs

Lines changed: 3 additions & 3 deletions
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, "-")?;
@@ -193,7 +193,7 @@ mod tests {
193193
Ok(duration) => duration,
194194
Err(_) => return Err(TestCaseError::reject("duration out of range")),
195195
};
196-
prop_assert_eq!(time::Duration::try_from(prost_duration.clone()).unwrap(), std_duration);
196+
prop_assert_eq!(time::Duration::try_from(prost_duration).unwrap(), std_duration);
197197

198198
if std_duration != time::Duration::default() {
199199
let neg_prost_duration = Duration {
@@ -220,7 +220,7 @@ mod tests {
220220
Ok(duration) => duration,
221221
Err(_) => return Err(TestCaseError::reject("duration out of range")),
222222
};
223-
prop_assert_eq!(time::Duration::try_from(prost_duration.clone()).unwrap(), std_duration);
223+
prop_assert_eq!(time::Duration::try_from(prost_duration).unwrap(), std_duration);
224224

225225
if std_duration != time::Duration::default() {
226226
let neg_prost_duration = Duration {

prost-types/src/timestamp.rs

Lines changed: 5 additions & 6 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)]
@@ -262,7 +261,7 @@ mod tests {
262261
) {
263262
let mut timestamp = Timestamp { seconds, nanos };
264263
timestamp.normalize();
265-
if let Ok(system_time) = SystemTime::try_from(timestamp.clone()) {
264+
if let Ok(system_time) = SystemTime::try_from(timestamp) {
266265
prop_assert_eq!(Timestamp::from(system_time), timestamp);
267266
}
268267
}

0 commit comments

Comments
 (0)