1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
mod generated;

use std::{fmt, num::NonZeroU8};

use Symbol;

pub use self::generated::*;

pub(crate) struct SymbolInfo(pub &'static str);

impl Symbol {
    pub(crate) fn new(idx: u16) -> Symbol {
        Symbol(NonZeroU8::new(idx as u8).unwrap())
    }

    pub(crate) fn info(&self) -> &SymbolInfo {
        let idx = (self.0.get() - 1) as usize;
        &generated::SYMBOLS[idx]
    }
}

impl fmt::Debug for Symbol {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        write!(f, "`{}", self.name())
    }
}