HashAlgorithm

Enum HashAlgorithm 

Source
pub enum HashAlgorithm {
    XxHash3,
}
Expand description

Hash algorithm selection

WDP specifies xxHash3 as the standard algorithm for error code hashing. xxHash3 is optimized for small inputs (15-30 byte error codes), making it ideal for WDP’s use case.

Note: This enum is kept for API compatibility but only xxHash3 is WDP-compliant.

Variants§

§

XxHash3

xxHash3 - WDP-specified algorithm (default)

  • Speed: ~30 GB/s
  • Optimized for small inputs (perfect for error codes!)
  • Security: NOT cryptographically secure (not needed for error codes)
  • Cross-platform: C, Python, JS, Go, Java, Rust, etc.
  • Standard: WDP Part 5 mandates xxHash3 with seed 0x000031762D706477

Implementations§

Source§

impl HashAlgorithm

Source

pub fn as_str(&self) -> &'static str

Get the algorithm name as a string

Examples found in repository?
examples/global_config.rs (line 43)
29fn main() {
30    println!("🦆 WDP-Compliant Hash Configuration Example");
31    println!("===========================================\n");
32
33    // 1. Default behavior (WDP-compliant)
34    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    // 2. Load global configuration
41    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    // 3. Per-diagnostic seed overrides (for testing/isolation)
50    println!("3. Custom Seed Override (for testing)");
51
52    // Override seed (e.g., for tenant isolation in tests)
53    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    // No override (uses global)
59    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    // 4. Different error codes with same config
65    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    // 5. Configuration priority demonstration
81    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    // Check if environment variable is set
88    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}
Source

pub fn is_wdp_compliant(&self) -> bool

Check if algorithm is WDP-compliant

Returns true for xxHash3 (the only WDP-compliant algorithm).

Source

pub fn is_cross_language(&self) -> bool

Check if algorithm is cross-language compatible

xxHash3 is supported in C, Python, JS, Go, Java, Rust, and more.

Trait Implementations§

Source§

impl Clone for HashAlgorithm

Source§

fn clone(&self) -> HashAlgorithm

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HashAlgorithm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HashAlgorithm

Source§

fn default() -> HashAlgorithm

Returns the “default value” for a type. Read more
Source§

impl FromStr for HashAlgorithm

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parse algorithm from string (case-insensitive)

Only xxHash3 is WDP-compliant.

§Examples
use waddling_errors_hash::HashAlgorithm;
use std::str::FromStr;

assert_eq!(HashAlgorithm::from_str("xxHash3"), Ok(HashAlgorithm::XxHash3));
assert_eq!(HashAlgorithm::from_str("xxh3"), Ok(HashAlgorithm::XxHash3));
assert!(HashAlgorithm::from_str("unknown").is_err());
Source§

type Err = ParseHashAlgorithmError

The associated error which can be returned from parsing.
Source§

impl PartialEq for HashAlgorithm

Source§

fn eq(&self, other: &HashAlgorithm) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for HashAlgorithm

Source§

impl Eq for HashAlgorithm

Source§

impl StructuralPartialEq for HashAlgorithm

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.