2018-08-18 13:55:43 +03:00
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
2014-07-01 18:39:41 +02:00
|
|
|
|
2020-02-28 15:32:09 -07:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct InvalidErrorCode;
|
|
|
|
|
2015-01-30 21:44:27 +13:00
|
|
|
#[derive(Clone)]
|
2014-07-01 18:39:41 +02:00
|
|
|
pub struct Registry {
|
2023-02-25 20:14:10 +13:00
|
|
|
long_descriptions: FxHashMap<&'static str, &'static str>,
|
2014-07-01 18:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Registry {
|
2023-02-25 20:14:10 +13:00
|
|
|
pub fn new(long_descriptions: &[(&'static str, &'static str)]) -> Registry {
|
2020-05-04 11:52:15 -07:00
|
|
|
Registry { long_descriptions: long_descriptions.iter().copied().collect() }
|
2014-07-01 18:39:41 +02:00
|
|
|
}
|
|
|
|
|
2020-02-28 15:32:09 -07:00
|
|
|
/// Returns `InvalidErrorCode` if the code requested does not exist in the
|
2023-02-25 20:14:10 +13:00
|
|
|
/// registry.
|
|
|
|
pub fn try_find_description(&self, code: &str) -> Result<&'static str, InvalidErrorCode> {
|
2020-05-04 11:52:15 -07:00
|
|
|
self.long_descriptions.get(code).copied().ok_or(InvalidErrorCode)
|
2014-07-01 18:39:41 +02:00
|
|
|
}
|
|
|
|
}
|