diff options
| author | Tshepang Lekhonkhobe <tshepang@gmail.com> | 2020-10-21 04:44:59 +0200 |
|---|---|---|
| committer | Tshepang Lekhonkhobe <tshepang@gmail.com> | 2020-10-21 04:44:59 +0200 |
| commit | 628fb9ff4a36c706789980276c165c4f013780cf (patch) | |
| tree | a5a65282394bf565d0ed58f048837f1769ea7966 | |
| parent | c38ddb8040edce1b05bc09a0e8439472e9f67623 (diff) | |
| download | rust-628fb9ff4a36c706789980276c165c4f013780cf.tar.gz rust-628fb9ff4a36c706789980276c165c4f013780cf.zip | |
make concurrency helper more pleasant to read
| -rw-r--r-- | library/test/src/helpers/concurrency.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index 7e9bd50f556..c39a9b0ec02 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -1,18 +1,14 @@ //! Helper module which helps to determine amount of threads to be used //! during tests execution. -use std::env; -use std::thread; +use std::{env, num::NonZeroUsize, thread}; -#[allow(deprecated)] pub fn get_concurrency() -> usize { - match env::var("RUST_TEST_THREADS") { - Ok(s) => { - let opt_n: Option<usize> = s.parse().ok(); - match opt_n { - Some(n) if n > 0 => n, - _ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", s), - } + if let Ok(value) = env::var("RUST_TEST_THREADS") { + match value.parse::<NonZeroUsize>().ok() { + Some(n) => n.get(), + _ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", value), } - Err(..) => thread::available_concurrency().map(|n| n.get()).unwrap_or(1), + } else { + thread::available_concurrency().map(|n| n.get()).unwrap_or(1) } } |
