adze_concurrency_normalize_core/
lib.rs1#![forbid(unsafe_op_in_unsafe_fn)]
4#![deny(missing_docs)]
5#![cfg_attr(feature = "strict_api", deny(unreachable_pub))]
6#![cfg_attr(not(feature = "strict_api"), warn(unreachable_pub))]
7#![cfg_attr(feature = "strict_docs", deny(missing_docs))]
8#![cfg_attr(not(feature = "strict_docs"), allow(missing_docs))]
9
10pub const MIN_CONCURRENCY: usize = 1;
12
13#[must_use]
17pub const fn normalized_concurrency(concurrency: usize) -> usize {
18 if concurrency == 0 {
19 MIN_CONCURRENCY
20 } else {
21 concurrency
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::{MIN_CONCURRENCY, normalized_concurrency};
28
29 #[test]
30 fn minimum_concurrency_is_stable() {
31 assert_eq!(MIN_CONCURRENCY, 1);
32 }
33
34 #[test]
35 fn normalized_concurrency_is_never_zero() {
36 assert_eq!(normalized_concurrency(0), 1);
37 assert_eq!(normalized_concurrency(1), 1);
38 assert_eq!(normalized_concurrency(8), 8);
39 }
40}