Skip to content

Commit

Permalink
fix: Remove clone call when copy is implemented
Browse files Browse the repository at this point in the history
Clippy reports: warning: using `clone` on type `Timestamp` which implements the `Copy` trait
  • Loading branch information
caspermeijn committed Apr 26, 2024
1 parent 2ce0183 commit 4ca89a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion prost-types/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ mod tests {
};
assert_eq!(
expected,
format!("{}", DateTime::from(timestamp.clone())),
format!("{}", DateTime::from(timestamp)),
"timestamp: {:?}",
timestamp
);
Expand Down
6 changes: 3 additions & 3 deletions prost-types/src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl TryFrom<Duration> 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, "-")?;
Expand Down Expand Up @@ -193,7 +193,7 @@ mod tests {
Ok(duration) => duration,
Err(_) => return Err(TestCaseError::reject("duration out of range")),
};
prop_assert_eq!(time::Duration::try_from(prost_duration.clone()).unwrap(), std_duration);
prop_assert_eq!(time::Duration::try_from(prost_duration).unwrap(), std_duration);

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

if std_duration != time::Duration::default() {
let neg_prost_duration = Duration {
Expand Down
11 changes: 5 additions & 6 deletions prost-types/src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Timestamp, Timestamp> {
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.
Expand Down Expand Up @@ -201,7 +201,7 @@ impl TryFrom<Timestamp> for std::time::SystemTime {
type Error = TimestampError;

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

let system_time = if timestamp.seconds >= 0 {
Expand All @@ -211,8 +211,7 @@ impl TryFrom<Timestamp> for std::time::SystemTime {
timestamp
.seconds
.checked_neg()
.ok_or_else(|| TimestampError::OutOfSystemRange(timestamp.clone()))?
as u64,
.ok_or(TimestampError::OutOfSystemRange(timestamp))? as u64,
))
};

Expand All @@ -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)]
Expand Down Expand Up @@ -262,7 +261,7 @@ mod tests {
) {
let mut timestamp = Timestamp { seconds, nanos };
timestamp.normalize();
if let Ok(system_time) = SystemTime::try_from(timestamp.clone()) {
if let Ok(system_time) = SystemTime::try_from(timestamp) {
prop_assert_eq!(Timestamp::from(system_time), timestamp);
}
}
Expand Down

0 comments on commit 4ca89a0

Please sign in to comment.