use match_by_hash::match_by_hash; const fn hash(value: &str) -> usize { let mut result = 0; let bytes = value.as_bytes(); let mut i = 0; while i < bytes.len() { result = result * 420 + (bytes[i] as usize); i += 1; } result } #[test] fn default() { let result = match_by_hash!(match hash("k") { _ => 42, }); assert_eq!(result, 42); } #[test] fn keys() { let result = match_by_hash!(match hash("bac") { "a" => 1, "bac" => 2, "c" => 3, _ => 42, }); assert_eq!(result, 2); } const fn num_hash(num: usize) -> usize { num * 3 } #[test] fn numbers() { let result = match_by_hash!(match num_hash(5usize) { 5 => "right", 6 => "", 7 => "", _ => "", }); assert_eq!(result, "right"); }