Eliminated possible panics in Config::get_option.

This commit is contained in:
Aaron Weiss 2018-02-21 12:16:35 +01:00
parent 363629f400
commit 7d744529e6
No known key found for this signature in database
GPG key ID: 047D32DF25DC22EF

View file

@ -469,13 +469,10 @@ impl Config {
} }
/// Looks up the specified string in the options map. /// Looks up the specified string in the options map.
/// This uses indexing, and thus panics when the string is not present. pub fn get_option(&self, option: &str) -> Option<&str> {
/// This will also panic if used and there are no options. self.options.as_ref().and_then(|o| {
pub fn get_option(&self, option: &str) -> &str { o.get(&option.to_owned()).map(|s| &s[..])
self.options })
.as_ref()
.map(|o| &o[&option.to_owned()][..])
.unwrap()
} }
/// Gets whether or not to use a mock connection for testing. /// Gets whether or not to use a mock connection for testing.