Skip to main content

prolly/prolly/proximity/build/
parallel.rs

1use crate::prolly::error::Error;
2
3/// Runtime-only worker limit for independent construction work.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub struct BuildParallelism {
6    threads: usize,
7}
8
9impl BuildParallelism {
10    pub fn new(threads: usize) -> Result<Self, Error> {
11        if threads == 0 {
12            return Err(Error::InvalidProximityConfig {
13                reason: "build parallelism must be greater than zero".to_owned(),
14            });
15        }
16        Ok(Self { threads })
17    }
18
19    pub const fn serial() -> Self {
20        Self { threads: 1 }
21    }
22
23    pub const fn threads(self) -> usize {
24        self.threads
25    }
26}
27
28impl Default for BuildParallelism {
29    fn default() -> Self {
30        Self {
31            threads: rayon::current_num_threads().max(1),
32        }
33    }
34}