use std::path::PathBuf;
#[derive(Debug)]
pub struct Configuration {
pub input_files: Vec<PathBuf>,
pub output: String,
pub number_of_threads: u8,
pub quiet: bool
}
impl Configuration {
pub fn new() -> Configuration {
Configuration {
input_files: Vec::new(),
output: String::from("render.png"),
number_of_threads: default_threads(),
quiet: false,
}
}
pub fn add_input<'a>(&'a mut self, file: PathBuf) -> &'a mut Configuration {
self.input_files.push(file);
self
}
pub fn set_output<'a>(&'a mut self, file: String) -> &'a mut Configuration {
self.output = file;
self
}
pub fn set_threads<'a>(&'a mut self, num: u8) -> &'a mut Configuration {
self.number_of_threads = num;
self
}
pub fn set_quiet<'a>(&'a mut self, val: bool) -> &'a mut Configuration {
self.quiet = val;
self
}
}
pub fn default_threads() -> u8 {
let virtual_cores = num_cpus::get();
let threads = if virtual_cores > 1 {
virtual_cores - 1
} else {
virtual_cores
};
threads as u8
}