Kaynağa Gözat

Upgrade to rand 0.8

Jing Yang 5 yıl önce
ebeveyn
işleme
de5958bd60
2 değiştirilmiş dosya ile 11 ekleme ve 13 silme
  1. 1 1
      Cargo.toml
  2. 10 12
      src/network.rs

+ 1 - 1
Cargo.toml

@@ -11,7 +11,7 @@ bytes = "1.0"
 crossbeam-channel = "0.5.0"
 futures = { version = "0.3.8", default-features = false, features = ["thread-pool"] }
 parking_lot = "0.11.0"
-rand = "0.7.3"
+rand = "0.8.0"
 tokio = { version = "1.0", features = ["rt-multi-thread", "time", "parking_lot"] }
 
 [features]

+ 10 - 12
src/network.rs

@@ -168,7 +168,7 @@ impl Network {
         // Random delay before sending requests to server.
         if !reliable {
             let minor_delay =
-                thread_rng().gen_range(0, Self::MAX_MINOR_DELAY_MILLIS);
+                thread_rng().gen_range(0..Self::MAX_MINOR_DELAY_MILLIS);
             Self::delay_for_millis(minor_delay).await;
 
             // Random drop of a DROP_RATE / DROP_BASE chance.
@@ -199,14 +199,13 @@ impl Network {
             }
             // If the server does not exist, return error after a random delay.
             Err(e) => {
-                let long_delay = rand::thread_rng().gen_range(
-                    0,
-                    if long_delays {
-                        Self::MAX_LONG_DELAY_MILLIS
-                    } else {
-                        Self::MAX_SHORT_DELAY_MILLIS
-                    },
-                );
+                let long_delay_upper = if long_delays {
+                    Self::MAX_LONG_DELAY_MILLIS
+                } else {
+                    Self::MAX_SHORT_DELAY_MILLIS
+                };
+                let long_delay =
+                    rand::thread_rng().gen_range(0..long_delay_upper);
                 Self::delay_for_millis(long_delay).await;
                 Err(e)
             }
@@ -250,11 +249,10 @@ impl Network {
                 );
                 if should_reorder {
                     let long_delay_bound = thread_rng().gen_range(
-                        0,
-                        Self::LONG_REORDERING_RANDOM_DELAY_BOUND_MILLIS,
+                        0..Self::LONG_REORDERING_RANDOM_DELAY_BOUND_MILLIS,
                     );
                     let long_delay = Self::LONG_REORDERING_BASE_DELAY_MILLIS
-                        + thread_rng().gen_range(0, 1 + long_delay_bound);
+                        + thread_rng().gen_range(0..1 + long_delay_bound);
                     Self::delay_for_millis(long_delay).await;
                     // Falling through to send the result.
                 }