Skip to content

Commit 1c66688

Browse files
authored
Rollup merge of #78065 - tshepang:nits, r=dtolnay
make concurrency helper more pleasant to read
2 parents bdeace9 + 628fb9f commit 1c66688

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed
+7-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
//! Helper module which helps to determine amount of threads to be used
22
//! during tests execution.
3-
use std::env;
4-
use std::thread;
3+
use std::{env, num::NonZeroUsize, thread};
54

6-
#[allow(deprecated)]
75
pub fn get_concurrency() -> usize {
8-
match env::var("RUST_TEST_THREADS") {
9-
Ok(s) => {
10-
let opt_n: Option<usize> = s.parse().ok();
11-
match opt_n {
12-
Some(n) if n > 0 => n,
13-
_ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", s),
14-
}
6+
if let Ok(value) = env::var("RUST_TEST_THREADS") {
7+
match value.parse::<NonZeroUsize>().ok() {
8+
Some(n) => n.get(),
9+
_ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", value),
1510
}
16-
Err(..) => thread::available_concurrency().map(|n| n.get()).unwrap_or(1),
11+
} else {
12+
thread::available_concurrency().map(|n| n.get()).unwrap_or(1)
1713
}
1814
}

0 commit comments

Comments
 (0)