diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2021-04-06 21:24:59 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2021-04-09 13:13:58 +0200 |
commit | 5d029cbf42621452666bd084f7beecb7d3d885a4 (patch) | |
tree | 21219c5864beac97ff5c55c78b436918034adcd6 /openpgp/src/types | |
parent | 9424cd350f32a97479a74d919c646f9e26c2ebce (diff) |
Lint: Remove unnecessary conversions.
- https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
Diffstat (limited to 'openpgp/src/types')
-rw-r--r-- | openpgp/src/types/timestamp.rs | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/openpgp/src/types/timestamp.rs b/openpgp/src/types/timestamp.rs index 7fe80a42..78c5180f 100644 --- a/openpgp/src/types/timestamp.rs +++ b/openpgp/src/types/timestamp.rs @@ -341,44 +341,57 @@ impl Duration { /// Returns a `Duration` with the given number of minutes, if /// representable. pub fn minutes(n: u32) -> Result<Duration> { - 60u32.checked_mul(n).ok_or(()) - .map(Self::seconds) - .map_err(|_| Error::InvalidArgument( - format!("Not representable: {} minutes in seconds exceeds u32", - n)).into()) + match 60u32.checked_mul(n) { + Some(val) => Ok(Self::seconds(val)), + None => { + Err(Error::InvalidArgument(format!( + "Not representable: {} minutes in seconds exceeds u32", + n + )).into()) + } + } } /// Returns a `Duration` with the given number of hours, if /// representable. pub fn hours(n: u32) -> Result<Duration> { - 60u32.checked_mul(n) - .ok_or(Error::InvalidArgument("".into()).into()) - .and_then(Self::minutes) - .map_err(|_| Error::InvalidArgument( - format!("Not representable: {} hours in seconds exceeds u32", - n)).into()) + match 60u32.checked_mul(n) { + Some(val) => Self::minutes(val), + None => { + Err(Error::InvalidArgument(format!( + "Not representable: {} hours in seconds exceeds u32", + n + )).into()) + } + } } /// Returns a `Duration` with the given number of days, if /// representable. pub fn days(n: u32) -> Result<Duration> { - 24u32.checked_mul(n) - .ok_or(Error::InvalidArgument("".into()).into()) - .and_then(Self::hours) - .map_err(|_| Error::InvalidArgument( - format!("Not representable: {} days in seconds exceeds u32", - n)).into()) + match 24u32.checked_mul(n) { + Some(val) => Self::hours(val), + None => { + Err(Error::InvalidArgument(format!( + "Not representable: {} days in seconds exceeds u32", + n + )).into()) + } + } } /// Returns a `Duration` with the given number of weeks, if /// representable. pub fn weeks(n: u32) -> Result<Duration> { - 7u32.checked_mul(n) - .ok_or(Error::InvalidArgument("".into()).into()) - .and_then(Self::days) - .map_err(|_| Error::InvalidArgument( - format!("Not representable: {} weeks in seconds exceeds u32", - n)).into()) + match 7u32.checked_mul(n) { + Some(val) => Self::days(val), + None => { + Err(Error::InvalidArgument(format!( + "Not representable: {} weeks in seconds exceeds u32", + n + )).into()) + } + } } /// Returns a `Duration` with the given number of years, if |