pub struct Key { /* private fields */ }Expand description
The identity of something an application names, built from any hashable value.
A key carries the value’s type as well as its hash, so keys built from equal values of the same type are equal and keys of different types never are. An application’s own enums are therefore its natural keys, and one name cannot collide with another concern’s.
use urushi::Key;
#[derive(Hash)]
enum Pane {
Preview,
Chart,
}
assert_eq!(Key::of(&Pane::Preview), Key::of(&Pane::Preview));
assert_ne!(Key::of(&Pane::Preview), Key::of(&Pane::Chart));
assert_eq!(Key::from("preview"), Key::of(&"preview"));
assert_eq!(format!("{:?}", Key::from("preview")), "Key(preview)");The value itself is not kept: a key is a type and a hash, which is what lets it name anything without owning it. Two distinct values of one type whose hashes collide are therefore one key, as they are in any hash map.
What it does keep is a label to print, and only one that costs nothing to
hold: the literal for a key built from one, and the type’s name otherwise.
A key stays Copy, and a log line says which key rather than which hash.