Macro stacko::new_key_types
source · [−]macro_rules! new_key_types {
($(#[$meta:meta])* $vis:vis struct $name:ident; $($other:tt)*) => { ... };
() => { ... };
}
Expand description
Defines a new type of Key
.
📌 Using different key types for different Stacko
s can prevent using the wrong
key to access a value in the wrong Stacko
.
Examples
new_key_types! {
/// This is a special key type identifying fruits stored in a Stacko.
pub struct FruitKey;
/// Another key type for vegetables which cannot be used with the `fruits` Stacko.
pub struct VegetableKey;
}
let fruits = Stacko::<&'static str, FruitKey>::new();
let (apple_key, _) = fruits.push("Apple");
let (banana_key, _) = fruits.push("Banana");
assert_eq!(fruits[apple_key], "Apple");