1 use rustc_data_structures::fx::FxHashMap;
4 pub struct InvalidErrorCode;
8 long_descriptions: FxHashMap<&'static str, Option<&'static str>>,
12 pub fn new(long_descriptions: &[(&'static str, Option<&'static str>)]) -> Registry {
13 Registry { long_descriptions: long_descriptions.iter().copied().collect() }
16 /// This will panic if an invalid error code is passed in
17 pub fn find_description(&self, code: &str) -> Option<&'static str> {
18 self.long_descriptions[code]
20 /// Returns `InvalidErrorCode` if the code requested does not exist in the
21 /// registry. Otherwise, returns an `Option` where `None` means the error
22 /// code is valid but has no extended information.
23 pub fn try_find_description(
26 ) -> Result<Option<&'static str>, InvalidErrorCode> {
27 self.long_descriptions.get(code).copied().ok_or(InvalidErrorCode)