#[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;
}
}