Refactoring: Use function chaining rather than matching

This commit is contained in:
Matthias Beyer 2018-01-04 23:09:30 +01:00
parent dd66936e48
commit 40490c10d6

View file

@ -42,40 +42,36 @@ impl Readline {
let histignspace = c.lookup("ui.cli.readline_history_ignore_space").ok_or(IEK::ConfigError)?; let histignspace = c.lookup("ui.cli.readline_history_ignore_space").ok_or(IEK::ConfigError)?;
let prompt = c.lookup("ui.cli.readline_prompt").ok_or(IEK::ConfigError)?; let prompt = c.lookup("ui.cli.readline_prompt").ok_or(IEK::ConfigError)?;
let histfile = match histfile { let histfile = histfile
Value::String(s) => PathBuf::from(s), .as_str()
_ => Err(IE::from_kind(IEK::ConfigTypeError)) .map(PathBuf::from)
.ok_or(IE::from_kind(IEK::ConfigTypeError))
.chain_err(|| IEK::ConfigError) .chain_err(|| IEK::ConfigError)
.chain_err(|| IEK::ReadlineError) .chain_err(|| IEK::ReadlineError)?;
}?;
let histsize = match histsize { let histsize = histsize
Value::Integer(i) => i, .as_int()
_ => Err(IE::from_kind(IEK::ConfigTypeError)) .ok_or(IE::from_kind(IEK::ConfigTypeError))
.chain_err(|| IEK::ConfigError) .chain_err(|| IEK::ConfigError)
.chain_err(|| IEK::ReadlineError) .chain_err(|| IEK::ReadlineError)?;
}?;
let histigndups = match histigndups { let histigndups = histigndups
Value::Boolean(b) => b, .as_bool()
_ => Err(IE::from_kind(IEK::ConfigTypeError)) .ok_or(IE::from_kind(IEK::ConfigTypeError))
.chain_err(|| IEK::ConfigError) .chain_err(|| IEK::ConfigError)
.chain_err(|| IEK::ReadlineError) .chain_err(|| IEK::ReadlineError)?;
}?;
let histignspace = match histignspace { let histignspace = histignspace
Value::Boolean(b) => b, .as_bool()
_ => Err(IE::from_kind(IEK::ConfigTypeError)) .ok_or(IE::from_kind(IEK::ConfigTypeError))
.chain_err(|| IEK::ConfigError) .chain_err(|| IEK::ConfigError)
.chain_err(|| IEK::ReadlineError) .chain_err(|| IEK::ReadlineError)?;
}?;
let prompt = match prompt { let prompt = prompt
Value::String(s) => s, .as_str()
_ => Err(IE::from_kind(IEK::ConfigTypeError)) .ok_or(IE::from_kind(IEK::ConfigTypeError))
.chain_err(|| IEK::ConfigError) .chain_err(|| IEK::ConfigError)
.chain_err(|| IEK::ReadlineError) .chain_err(|| IEK::ReadlineError)?;
}?;
let config = Config::builder(). let config = Config::builder().
.max_history_size(histsize) .max_history_size(histsize)