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
58
59
60
61
62
63
64
65
66
67
68
69
#[derive(Debug,Clone)]
pub struct Config {
thread_count: usize,
limit_result_channel_buffer: usize,
limit_task_channel_buffer: usize,
}
quick_error! {
#[derive(Debug)]
pub enum ConfigError {
InvalidThreadCount {
description("Field thread_count shall be positive")
}
}
}
impl Config {
pub fn new(thread_count: usize) -> Result<Config,ConfigError> {
let result = Config {
thread_count: thread_count,
limit_result_channel_buffer: 0,
limit_task_channel_buffer: 0,
};
result.check_configuration()?;
Ok(result)
}
fn check_configuration(&self) -> Result<(),ConfigError> {
if self.thread_count <= 0 {
return Err(ConfigError::InvalidThreadCount);
}
Ok(())
}
pub fn get_thread_count(&self) -> usize {
return self.thread_count;
}
pub fn set_limit_result_channel(&mut self,value: usize) -> Result<&mut Self,ConfigError> {
self.limit_result_channel_buffer = value;
self.check_configuration()?;
Ok(self)
}
pub fn get_limit_result_channel(&self) -> usize {
return self.limit_result_channel_buffer;
}
pub fn set_limit_task_channel(&mut self,value: usize) -> Result<&mut Self,ConfigError> {
self.limit_task_channel_buffer = value;
self.check_configuration()?;
Ok(self)
}
pub fn get_limit_task_channel(&self) -> usize {
return self.limit_task_channel_buffer;
}
}