Skip to content

Commit

Permalink
Use fallible conversion for tv_nsec in TimeSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
sirhcel committed Oct 20, 2024
1 parent d630718 commit 65b0fc4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/sys/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ impl TimeSpec {
self.0.tv_nsec
}

#[allow(clippy::unnecessary_fallible_conversions)]
pub fn try_from_duration(
duration: Duration,
) -> Result<Self, TryFromDurationError> {
Expand All @@ -399,7 +400,12 @@ impl TimeSpec {
.as_secs()
.try_into()
.map_err(|_| TryFromDurationError)?;
ts.tv_nsec = duration.subsec_nanos().into();
// There are targets with tv_nsec being i32. Use the fallible conversion for all targets as
// we are returning a Result due to the previous conversion anyway.
ts.tv_nsec = duration
.subsec_nanos()
.try_into()
.map_err(|_| TryFromDurationError)?;
Ok(TimeSpec(ts))
}

Expand Down

0 comments on commit 65b0fc4

Please sign in to comment.