global_config/
global_config.rs1use waddling_errors_hash::{
26 WDP_SEED, apply_overrides, compute_hash, compute_hash_with_config, load_global_config,
27};
28
29fn main() {
30 println!("š¦ WDP-Compliant Hash Configuration Example");
31 println!("===========================================\n");
32
33 println!("1. WDP-Compliant Default Configuration");
35 println!(" Algorithm: xxHash3 (WDP-specified)");
36 println!(" Seed: 0x{:016X} (WDP v1 seed)", WDP_SEED);
37 let default_hash = compute_hash("E.AUTH.TOKEN.001");
38 println!(" Hash: {}\n", default_hash);
39
40 println!("2. Load Global Configuration");
42 let global_config = load_global_config();
43 println!(" Algorithm: {}", global_config.algorithm.as_str());
44 println!(" Seed: 0x{:016X}", global_config.seed);
45
46 let global_hash = compute_hash_with_config("E.AUTH.TOKEN.001", &global_config);
47 println!(" Hash: {}\n", global_hash);
48
49 println!("3. Custom Seed Override (for testing)");
51
52 let custom_seed_config = apply_overrides(&global_config, Some(0x12345678));
54 let custom_seed_hash = compute_hash_with_config("E.AUTH.TOKEN.001", &custom_seed_config);
55 println!(" Override seed to 0x12345678:");
56 println!(" Hash: {}", custom_seed_hash);
57
58 let no_override_config = apply_overrides(&global_config, None);
60 let no_override_hash = compute_hash_with_config("E.AUTH.TOKEN.001", &no_override_config);
61 println!(" No override (same as global):");
62 println!(" Hash: {}\n", no_override_hash);
63
64 println!("4. Multiple Error Codes (same config)");
66 let codes = [
67 "E.AUTH.TOKEN.001",
68 "E.AUTH.SESSION.002",
69 "E.DB.CONNECTION.003",
70 "E.CACHE.MISS.004",
71 ];
72
73 for code in &codes {
74 let hash = compute_hash_with_config(code, &global_config);
75 println!(" {} ā {}", code, hash);
76 }
77
78 println!("\nā
WDP-compliant hashes ensure cross-platform consistency!");
79
80 println!("\n5. Configuration Priority Order");
82 println!(" 1. Per-diagnostic seed override (highest)");
83 println!(" 2. Environment variable WADDLING_HASH_SEED");
84 println!(" 3. Cargo.toml hash_seed");
85 println!(" 4. WDP default seed (0x000031762D706477)\n");
86
87 match option_env!("WADDLING_HASH_SEED") {
89 Some(seed) => {
90 println!(" š Environment variable detected:");
91 println!(" WADDLING_HASH_SEED={}", seed);
92 }
93 None => {
94 println!(" ā¹ļø No environment variable set");
95 println!(" Using WDP default seed");
96 }
97 }
98
99 println!("\nšÆ WDP ensures cross-language compatibility!");
100 println!(" Same error code produces same hash in:");
101 println!(" - Rust, Python, JavaScript, Go, Java, C, etc.");
102}