bitcoin_internals/hex/
mod.rs1pub mod buf_encoder;
6pub mod display;
7
8pub use buf_encoder::BufEncoder;
9
10pub mod exts {
12 pub use super::display::DisplayHex;
13}
14
15#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
17pub enum Case {
18 Lower,
22
23 Upper,
25}
26
27impl Default for Case {
28 fn default() -> Self { Case::Lower }
29}
30
31impl Case {
32 #[inline]
36 #[rustfmt::skip]
37 pub(crate) fn table(self) -> &'static [u8; 16] {
38 static LOWER: [u8; 16] = [b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'a', b'b', b'c', b'd', b'e', b'f'];
39 static UPPER: [u8; 16] = [b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'A', b'B', b'C', b'D', b'E', b'F'];
40
41 match self {
42 Case::Lower => &LOWER,
43 Case::Upper => &UPPER,
44 }
45 }
46}
47
48#[inline]
52pub(crate) fn byte_to_hex(byte: u8, table: &[u8; 16]) -> [u8; 2] {
53 [table[usize::from(byte.wrapping_shr(4))], table[usize::from(byte & 0x0F)]]
54}