1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::{OnPoolDropBehavior, ScheduledThreadPool};
pub struct NumThreadsStage(pub(crate) ());
impl NumThreadsStage {
pub fn num_threads<'a>(self, num_threads: usize) -> FinalStage<'a> {
assert!(num_threads > 0, "num_threads must be positive");
FinalStage {
num_threads,
thread_name_pattern: None,
on_drop_behavior: OnPoolDropBehavior::CompletePendingScheduled,
}
}
}
pub struct FinalStage<'a> {
pub(crate) num_threads: usize,
pub(crate) thread_name_pattern: Option<&'a str>,
pub(crate) on_drop_behavior: OnPoolDropBehavior,
}
impl<'a> FinalStage<'a> {
pub fn thread_name_pattern(mut self, thread_name_pattern: &'a str) -> Self {
self.thread_name_pattern = Some(thread_name_pattern);
self
}
pub fn on_drop_behavior(mut self, on_drop_behavior: OnPoolDropBehavior) -> Self {
self.on_drop_behavior = on_drop_behavior;
self
}
pub fn build(self) -> ScheduledThreadPool {
ScheduledThreadPool::new_inner(self)
}
}