Browse Source

Resolved compilation and borrowing errors

develop
Drew Short 6 years ago
parent
commit
a6185c5d18
  1. 20
      src/args.rs

20
src/args.rs

@ -4,12 +4,12 @@ use clap::ArgMatches;
use config::model::Config;
fn get_config_for_string(arg_value: Option<&str>, config_value: Option<String>, default_value: &str) -> String {
fn get_config_for_string(arg_value: Option<&str>, config_value: &Option<String>, default_value: &str) -> String {
String::from(match arg_value {
Some(v) => v,
None => match c.server.host {
None => match config_value {
Some(host) => host,
None => default_host,
None => default_value,
}
})
}
@ -26,22 +26,22 @@ fn get_config_for_number<T: FromStr>(arg_value: Option<&str>, config_value: Opti
fn get_number<T: FromStr>(arg_value: Option<&str>, default_value: T) -> T {
match arg_value {
Some(value) => port.parse::<T>().unwrap_or(default_port),
None => default_port
Some(value) => value.parse::<T>().unwrap_or(default_value),
None => default_value
}
}
pub fn get_host(args: &ArgMatches, config: &Option<Config>, default_host: &str) -> String {
let arg_value = args.value_of("host");
match config {
Some(c) => get_config_for_string(arg_value, c.server.host, default_host),
match &config {
Some(c) => get_config_for_string(arg_value, &c.server.host, default_host),
None => String::from(arg_value.unwrap_or(default_host))
}.clone()
}
pub fn get_port(args: &ArgMatches, config: &Option<Config>, default_port: i16) -> i16 {
let arg_value = args.value_of("port");
match config {
match &config {
Some(c) => get_config_for_number(arg_value, c.server.port, default_port),
None => get_number(arg_value, default_port)
}
@ -49,8 +49,8 @@ pub fn get_port(args: &ArgMatches, config: &Option<Config>, default_port: i16) -
pub fn get_workers(args: &ArgMatches, config: &Option<Config>, default_workers: usize) -> usize {
let arg_value = args.value_of("workers");
match config {
match &config {
Some(c) => get_config_for_number(arg_value, c.server.workers, default_workers),
None => get_number(args_value, default_workers)
None => get_number(arg_value, default_workers)
}
}
Loading…
Cancel
Save