rustc_errors/
registry.rs

1use rustc_data_structures::fx::FxHashMap;
2
3use crate::ErrCode;
4
5#[derive(Debug)]
6pub struct InvalidErrorCode;
7
8#[derive(Clone)]
9pub struct Registry {
10    long_descriptions: FxHashMap<ErrCode, &'static str>,
11}
12
13impl Registry {
14    pub fn new(long_descriptions: &[(ErrCode, &'static str)]) -> Registry {
15        Registry { long_descriptions: long_descriptions.iter().copied().collect() }
16    }
17
18    /// Returns `InvalidErrorCode` if the code requested does not exist in the
19    /// registry.
20    pub fn try_find_description(&self, code: ErrCode) -> Result<&'static str, InvalidErrorCode> {
21        self.long_descriptions.get(&code).copied().ok_or(InvalidErrorCode)
22    }
23}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy