Generate Rust phf map for error codes
(args)
| 87 | |
| 88 | |
| 89 | def gen_error_codes_rust(args): |
| 90 | """Generate Rust phf map for error codes""" |
| 91 | yield "// Maps encoded (lib, reason) -> error mnemonic" |
| 92 | yield '// Example: encode_error_key(20, 134) -> "CERTIFICATE_VERIFY_FAILED"' |
| 93 | yield "// Key encoding: (lib << 32) | reason" |
| 94 | yield "pub static ERROR_CODES: phf::Map<u64, &'static str> = phf_map! {" |
| 95 | for reason, libname, errname, num in args.reasons: |
| 96 | if libname not in args.lib2errnum: |
| 97 | continue |
| 98 | lib_num = args.lib2errnum[libname] |
| 99 | # Encode (lib, reason) as single u64 |
| 100 | key = (lib_num << 32) | num |
| 101 | yield f' {key}u64 => "{errname}",' |
| 102 | yield "};" |
| 103 | yield "" |
| 104 | |
| 105 | |
| 106 | def main(): |