Skip to content

Commit f5163ad

Browse files
committed
Remove <integer>::max_value() to suppress clippy::legacy_numeric_constants warning
1 parent 1b5051a commit f5163ad

File tree

4 files changed

+15
-60
lines changed

4 files changed

+15
-60
lines changed

src/aq.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,7 @@ impl DeqOptions {
779779
/// Set the time to wait for a message matching the search
780780
/// criteria.
781781
pub fn set_wait(&mut self, val: &Duration) -> Result<()> {
782-
let secs = val.as_secs();
783-
let secs = if secs > u32::max_value().into() {
784-
u32::max_value()
785-
} else {
786-
secs as u32
787-
};
782+
let secs = val.as_secs().try_into().unwrap_or(u32::MAX);
788783
chkerr!(self.ctxt(), dpiDeqOptions_setWait(self.handle, secs));
789784
Ok(())
790785
}
@@ -1077,16 +1072,12 @@ where
10771072
/// [`MessageState::Waiting`]: MessageState#variant.Waiting
10781073
/// [`MessageState::Ready`]: MessageState#variant.Ready
10791074
pub fn set_delay(&mut self, val: &Duration) -> Result<()> {
1080-
let secs = val.as_secs();
1081-
if secs > i32::max_value() as u64 {
1082-
Err(Error::out_of_range(format!("too long duration {:?}", val)))
1083-
} else {
1084-
chkerr!(
1085-
self.ctxt(),
1086-
dpiMsgProps_setDelay(self.handle(), secs as i32)
1087-
);
1088-
Ok(())
1089-
}
1075+
let secs = val
1076+
.as_secs()
1077+
.try_into()
1078+
.map_err(|_| Error::out_of_range(format!("too long duration {:?}", val)))?;
1079+
chkerr!(self.ctxt(), dpiMsgProps_setDelay(self.handle(), secs));
1080+
Ok(())
10901081
}
10911082

10921083
/// Sets the name of the queue to which the message is moved if it cannot be
@@ -1117,16 +1108,12 @@ where
11171108
/// [`MessageState::Ready`]: MessageState#variant.Ready
11181109
/// [`MessageState::Expired`]: MessageState#variant.Expired
11191110
pub fn set_expiration(&mut self, val: &Duration) -> Result<()> {
1120-
let secs = val.as_secs();
1121-
if secs > i32::max_value() as u64 {
1122-
Err(Error::out_of_range(format!("too long duration {:?}", val)))
1123-
} else {
1124-
chkerr!(
1125-
self.ctxt(),
1126-
dpiMsgProps_setExpiration(self.handle(), secs as i32)
1127-
);
1128-
Ok(())
1129-
}
1111+
let secs = val
1112+
.as_secs()
1113+
.try_into()
1114+
.map_err(|_| Error::out_of_range(format!("too long duration {:?}", val)))?;
1115+
chkerr!(self.ctxt(), dpiMsgProps_setExpiration(self.handle(), secs));
1116+
Ok(())
11301117
}
11311118

11321119
/// Sets the id of the message in the last queue that generated this

src/connection.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use crate::sql_type::ObjectTypeInternal;
4141
use crate::sql_type::ToSql;
4242
use crate::to_odpi_str;
4343
use crate::to_rust_str;
44-
use crate::util::duration_to_msecs;
4544
use crate::AssertSend;
4645
use crate::AssertSync;
4746
#[cfg(doc)]
@@ -1320,7 +1319,7 @@ impl Connection {
13201319
/// ```
13211320
pub fn set_call_timeout(&self, dur: Option<Duration>) -> Result<()> {
13221321
if let Some(dur) = dur {
1323-
let msecs = duration_to_msecs(dur).ok_or_else(|| {
1322+
let msecs = dur.as_millis().try_into().map_err(|_| {
13241323
Error::out_of_range(format!(
13251324
"too long duration {:?}. It must be less than 49.7 days",
13261325
dur

src/sql_value.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ use crate::Result;
5959
macro_rules! flt_to_int {
6060
($expr:expr, $src_type:ident, $dest_type:ident) => {{
6161
let src_val = $expr;
62-
if $dest_type::min_value() as $src_type <= src_val
63-
&& src_val <= $dest_type::max_value() as $src_type
64-
{
62+
if $dest_type::MIN as $src_type <= src_val && src_val <= $dest_type::MAX as $src_type {
6563
Ok(src_val as $dest_type)
6664
} else {
6765
Err(Error::out_of_range(format!(

src/util.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::ffi::CString;
2222
use std::fmt;
2323
use std::result;
2424
use std::str;
25-
use std::time::Duration;
2625

2726
#[cfg_attr(unix, path = "util/unix.rs")]
2827
#[cfg_attr(windows, path = "util/windows.rs")]
@@ -201,18 +200,6 @@ pub fn write_literal(
201200
}
202201
}
203202

204-
pub fn duration_to_msecs(dur: Duration) -> Option<u32> {
205-
let msecs = dur
206-
.as_secs()
207-
.checked_mul(1000)?
208-
.checked_add(dur.subsec_nanos() as u64 / 1_000_000)?;
209-
if msecs <= u32::max_value() as u64 {
210-
Some(msecs as u32)
211-
} else {
212-
None
213-
}
214-
}
215-
216203
pub fn string_into_c_string(s: String, name: &str) -> Result<CString> {
217204
CString::new(s).map_err(|err| {
218205
Error::invalid_argument(format!("{} cannot contain nul characters", name)).add_source(err)
@@ -281,20 +268,4 @@ mod tests {
281268
Ok(vec![0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0])
282269
);
283270
}
284-
285-
#[test]
286-
fn test_duration_to_msecs() {
287-
assert_eq!(duration_to_msecs(Duration::new(0, 0)), Some(0));
288-
assert_eq!(duration_to_msecs(Duration::from_nanos(999_999)), Some(0));
289-
assert_eq!(duration_to_msecs(Duration::from_nanos(1_000_000)), Some(1));
290-
assert_eq!(
291-
duration_to_msecs(Duration::from_millis(u32::max_value() as u64)),
292-
Some(u32::max_value())
293-
);
294-
assert_eq!(
295-
duration_to_msecs(Duration::from_millis(u32::max_value() as u64 + 1)),
296-
None
297-
);
298-
assert_eq!(duration_to_msecs(Duration::new(50 * 24 * 60 * 60, 0)), None);
299-
}
300271
}

0 commit comments

Comments
 (0)