network_communicator/
config.rs1#[derive(Debug,Clone)]
3pub struct Config {
4 thread_count: usize,
5 limit_result_channel_buffer: usize,
6 limit_task_channel_buffer: usize,
7}
8
9quick_error! {
10 #[derive(Debug)]
12 pub enum ConfigError {
13 InvalidThreadCount {
15 description("Field thread_count shall be positive")
16 }
17 }
18}
19
20
21impl Config {
22 pub fn new(thread_count: usize) -> Result<Config,ConfigError> {
25 let result = Config {
26 thread_count: thread_count,
27 limit_result_channel_buffer: 0,
28 limit_task_channel_buffer: 0,
29 };
30 result.check_configuration()?;
31 Ok(result)
32 }
33
34 fn check_configuration(&self) -> Result<(),ConfigError> {
35 if self.thread_count <= 0 {
36 return Err(ConfigError::InvalidThreadCount);
37 }
38 Ok(())
39 }
40
41 pub fn get_thread_count(&self) -> usize {
43 return self.thread_count;
44 }
45
46 pub fn set_limit_result_channel(&mut self,value: usize) -> Result<&mut Self,ConfigError> {
48 self.limit_result_channel_buffer = value;
49 self.check_configuration()?;
50 Ok(self)
51 }
52
53 pub fn get_limit_result_channel(&self) -> usize {
55 return self.limit_result_channel_buffer;
56 }
57
58 pub fn set_limit_task_channel(&mut self,value: usize) -> Result<&mut Self,ConfigError> {
60 self.limit_task_channel_buffer = value;
61 self.check_configuration()?;
62 Ok(self)
63 }
64
65 pub fn get_limit_task_channel(&self) -> usize {
67 return self.limit_task_channel_buffer;
68 }
69}