Eliminated possible panics in Config::get_option.
This commit is contained in:
parent
363629f400
commit
7d744529e6
1 changed files with 4 additions and 7 deletions
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue