Repository: cassandra-rs/cassandra-rs (language: rust)

Issue:
[0.16] use std::time::Duration instead of time::Duration
Don't entirely know why this decision was made, but after an audit of the call-sites, it would appear that the std duration would be more than acceptable, and we can drop this extra dependency.

My hunch is that the necessary methods with std's duration were not added until rust v1.33, https://doc.rust-lang.org/std/time/struct.Duration.html#method.as_millis

our msrv is at-least 1.39 so this should be :+1: 


Discussion / hints:
Agree, let's fix this to use std's `Duration`. (In any case we should use `chrono` in favour of `time` - but if we can avoid both that's even better).

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 059b145..35d75a7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@ version number is tracked in the file `VERSION`.
 - Switched to using `parking_lot::Mutex` instead of `std::sync::Mutex` for
   `CassFuture` coordination.
 - Implemented `size_hint` on `ResultIterator`.
+- `time::Duration` has been replaced with `std::time::Duration`.
 
 ### Fixed
  - `CassResult::set_paging_state_token` was implemented incorrectly, namely, it did nothing,
diff --git a/Cargo.toml b/Cargo.toml
index aafbba7..392629d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,6 @@ clippy = {version = "0.0", optional = true}
 slog = "2"
 cassandra-cpp-sys = "0.12"
 decimal = "2"
-time = "0.2"
 uuid = "0.8"
 error-chain = "0.12"
 parking_lot = "0.11"
diff --git a/src/cassandra/cluster.rs b/src/cassandra/cluster.rs
index af9b23b..38edfcd 100644
--- a/src/cassandra/cluster.rs
+++ b/src/cassandra/cluster.rs
@@ -60,7 +60,7 @@ use std::net::Ipv4Addr;
 use std::os::raw::c_char;
 use std::result;
 use std::str::FromStr;
-use time::Duration;
+use std::time::Duration;
 
 /// A CQL protocol version is just an integer.
 pub type CqlProtocol = i32;
@@ -339,7 +339,7 @@ impl Cluster {
     /// Default: 5000ms
     pub fn set_connect_timeout(&mut self, timeout: Duration) -> &Self {
         unsafe {
-            cass_cluster_set_connect_timeout(self.0, timeout.whole_milliseconds() as u32);
+            cass_cluster_set_connect_timeout(self.0, timeout.as_millis() as u32);
         }
         self
     }
@@ -350,7 +350,7 @@ impl Cluster {
     /// Default: 12000ms
     pub fn set_request_timeout(&mut self, timeout: Duration) -> &Self {
         unsafe {
-            cass_cluster_set_request_timeout(self.0, timeout.whole_milliseconds() as u32);
+            cass_cluster_set_request_timeout(self.0, timeout.as_millis() as u32);
         }
         self
     }
@@ -503,9 +503,9 @@ impl Cluster {
             cass_cluster_set_latency_aware_routing_settings(
                 self.0,
                 exclusion_threshold,
-                scale.whole_milliseconds() as u64,
-                retry_period.whole_milliseconds() as u64,
-                update_rate.whole_milliseconds() as u64,
+                scale.as_millis() as u64,
+                retry_period.as_millis() as u64,
+                update_rate.as_millis() as u64,
                 min_measured,
             );
         }
@@ -550,7 +550,7 @@ impl Cluster {
             cass_cluster_set_tcp_keepalive(
                 self.0,
                 if enable { cass_true } else { cass_false },
-                delay.whole_seconds() as u32,
+                delay.as_secs() as u32,
             );
         }
         self
@@ -577,7 +577,7 @@ impl Cluster {
     /// Default: 30 seconds
     pub fn set_connection_heartbeat_interval(&mut self, hearbeat: Duration) -> &mut Self {
         unsafe {
-            cass_cluster_set_connection_heartbeat_interval(self.0, hearbeat.whole_seconds() as u32);
+            cass_cluster_set_connection_heartbeat_interval(self.0, hearbeat.as_secs() as u32);
             self
         }
     }
@@ -589,7 +589,7 @@ impl Cluster {
     /// Default: 60 seconds
     pub fn set_connection_idle_timeout(&mut self, timeout: Duration) -> &mut Self {
         unsafe {
-            cass_cluster_set_connection_idle_timeout(self.0, timeout.whole_seconds() as u32);
+            cass_cluster_set_connection_idle_timeout(self.0, timeout.as_secs() as u32);
             self
         }
     }
diff --git a/src/cassandra/statement.rs b/src/cassandra/statement.rs
index 4277751..f3b3f54 100644
--- a/src/cassandra/statement.rs
+++ b/src/cassandra/statement.rs
@@ -66,7 +66,7 @@ use crate::cassandra_sys::CassStatement as _Statement;
 use crate::cassandra_sys::CASS_UINT64_MAX;
 
 use std::os::raw::c_char;
-use time::Duration;
+use std::time::Duration;
 /// A statement object is an executable query. It represents either a regular
 /// (adhoc) statement or a prepared statement. It maintains the queries' parameter
 /// values along with query options (consistency level, paging state, etc.)
@@ -424,7 +424,7 @@ impl Statement {
         unsafe {
             let timeout_millis = match timeout {
                 None => CASS_UINT64_MAX as u64,
-                Some(time) => time.whole_milliseconds() as u64,
+                Some(time) => time.as_millis() as u64,
             };
             cass_statement_set_request_timeout(self.0, timeout_millis);
         }
diff --git a/src/cassandra/time.rs b/src/cassandra/time.rs
index 15e7779..da3e749 100644
--- a/src/cassandra/time.rs
+++ b/src/cassandra/time.rs
@@ -7,7 +7,8 @@ use crate::cassandra_sys::cass_timestamp_gen_server_side_new;
 use crate::cassandra_sys::CassTimestampGen as _TimestampGen;
 // use cassandra_sys::cass_date_from_epoch;
 // use cassandra_sys::cass_date_time_to_epoch;
-use time::Duration;
+
+use std::time::Duration;
 
 /// Generators of client-side, microsecond-precision timestamps.
 /// <b>Note:</b> This generator is thread-safe and can be shared by multiple sessions.
@@ -40,7 +41,7 @@ impl TimestampGen {
     /// Converts a unix timestamp (in seconds) to the Cassandra "time" type. The "time" type
     /// represents the number of nanoseconds since midnight (range 0 to 86399999999999).
     pub fn time_from_epoch(epoch_seconds: Duration) -> Time {
-        unsafe { Time(cass_time_from_epoch(epoch_seconds.whole_seconds())) }
+        unsafe { Time(cass_time_from_epoch(epoch_seconds.as_secs() as _)) }
     }
 
     /// Creates a new monotonically increasing timestamp generator. This generates


Test patch:
diff --git a/tests/basic.rs b/tests/basic.rs
index e1fec36..f3506a9 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -1,8 +1,8 @@
 mod help;
 
 use cassandra_cpp::*;
+use std::time::Duration;
 use std::time::SystemTime;
-use time::Duration;
 
 #[derive(Debug, PartialEq, Copy, Clone, Default)]
 struct Udt {
@@ -574,7 +574,7 @@ fn test_result() {
 #[test]
 fn test_statement_timeout() {
     let mut query = stmt!("SELECT * FROM system_schema.tables;");
-    query.set_statement_request_timeout(Some(Duration::milliseconds(30000 as i64)));
+    query.set_statement_request_timeout(Some(Duration::from_millis(30000)));
     let session = help::create_test_session();
     let result = session.execute(&query).wait().unwrap();