BuiltinHashKey
Proves the canonical default logical hash/equality operations for built-in keys. Admitted keys are integers, byte, IEEE numbers, bool, char, str and String. The compiler binds exact existing standard implementations; custom owners use an explicit HashKeyPolicy instead. No runtime witness, allocation, storage or lifecycle permission is introduced. Borrowed text keys still need live backing.
Module std.collections
import std.collections;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
BuiltinHashKey
pub concept BuiltinHashKey<Self>Proves the canonical default logical hash/equality operations for built-in keys. Admitted keys are integers, byte, IEEE numbers, bool, char, str and String. The compiler binds exact existing standard implementations; custom owners use an explicit HashKeyPolicy instead. No runtime witness, allocation, storage or lifecycle permission is introduced. Borrowed text keys still need live backing. Self: Exact supported key representation.
Example
module example.builtin_hash_key;
from std.collections import BuiltinHashKey;
fn SameKey<K>(Left: readonly K&, Right: readonly K&) -> bool where K: BuiltinHashKey {
if !K.EqualBuiltinKeys(Left, Right) { return false; }
// Equality implies equal hashes; unequal keys can still collide.
return K.HashBuiltinKey(Left) == K.HashBuiltinKey(Right);
}
fn Main() -> i32 {
if !SameKey(42_i32, 42_i32) || SameKey(42_i32, 43_i32) { return 1; }
if !SameKey('λ', 'λ') || SameKey('λ', 'A') { return 2; }
if !SameKey("key", "key") || SameKey("key", "other") { return 3; }
return 0;
}BuiltinHashKey.HashBuiltinKey
requires static fn HashBuiltinKey(Key: readonly Self&) -> u64;Hashes logical contents without allocation or retained borrowing. Key: Readonly key borrowed through the call. Return: Deterministic noncryptographic hash.
BuiltinHashKey.EqualBuiltinKeys
requires static fn EqualBuiltinKeys(Left: readonly Self&, Right: readonly Self&) -> bool;Compares exact logical key equivalence, including float zero/NaN policy. Left: First readonly key. Right: Second readonly key. Return: Whether both keys identify the same entry.