uv_configuration/concurrency.rs
1use std::num::NonZeroUsize;
2
3/// Concurrency limit settings.
4#[derive(Copy, Clone, Debug)]
5pub struct Concurrency {
6 /// The maximum number of concurrent downloads.
7 ///
8 /// Note this value must be non-zero.
9 pub downloads: usize,
10 /// The maximum number of concurrent builds.
11 ///
12 /// Note this value must be non-zero.
13 pub builds: usize,
14 /// The maximum number of concurrent installs.
15 ///
16 /// Note this value must be non-zero.
17 pub installs: usize,
18}
19
20impl Default for Concurrency {
21 fn default() -> Self {
22 Self {
23 downloads: Self::DEFAULT_DOWNLOADS,
24 builds: Self::threads(),
25 installs: Self::threads(),
26 }
27 }
28}
29
30impl Concurrency {
31 // The default concurrent downloads limit.
32 pub const DEFAULT_DOWNLOADS: usize = 50;
33
34 // The default concurrent builds and install limit.
35 pub fn threads() -> usize {
36 std::thread::available_parallelism()
37 .map(NonZeroUsize::get)
38 .unwrap_or(1)
39 }
40}