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 24, 2024
1 parent 2ce0183 commit 449b016
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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
8 changes: 4 additions & 4 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,7 +211,7 @@ impl TryFrom<Timestamp> for std::time::SystemTime {
timestamp
.seconds
.checked_neg()
.ok_or_else(|| TimestampError::OutOfSystemRange(timestamp.clone()))?
.ok_or(TimestampError::OutOfSystemRange(timestamp))?
as u64,
))
};
Expand All @@ -234,7 +234,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

0 comments on commit 449b016

Please sign in to comment.