Trait otter_api_tests::crates::otter_support::crates::slotmap::Key
source · [−]pub trait Key: From<KeyData> + Copy + Clone + Default + Eq + PartialEq<Self> + Ord + PartialOrd<Self> + Hash + Debug {
fn data(&self) -> KeyData;
fn null() -> Self { ... }
fn is_null(&self) -> bool { ... }
}
Expand description
Key used to access stored values in a slot map.
Do not use a key from one slot map in another. The behavior is safe but non-sensical (and might panic in case of out-of-bounds).
To prevent this, it is suggested to have a unique key type for each slot
map. You can create new key types using new_key_type!
, which makes a
new type identical to DefaultKey
, just with a different name.
Required Methods
Provided Methods
Creates a new key that is always invalid and distinct from any non-null
key. A null key can only be created through this method (or default
initialization of keys made with new_key_type!
, which calls this
method).
A null key is always invalid, but an invalid key (that is, a key that has been removed from the slot map) does not become a null key. A null is safe to use with any safe method of any slot map instance.
Examples
let mut sm = SlotMap::new();
let k = sm.insert(42);
let nk = DefaultKey::null();
assert!(nk.is_null());
assert!(k != nk);
assert_eq!(sm.get(nk), None);