l1x_sdk/store/lookup_map/
impls.rs1use std::borrow::Borrow;
2
3use borsh::{BorshDeserialize, BorshSerialize};
4
5use super::LookupMap;
6
7impl<K, V> Extend<(K, V)> for LookupMap<K, V>
8where
9 K: BorshSerialize + Ord,
10 V: BorshSerialize + BorshDeserialize,
11{
12 fn extend<I>(&mut self, iter: I)
13 where
14 I: IntoIterator<Item = (K, V)>,
15 {
16 for (key, value) in iter {
17 self.set(key, Some(value))
18 }
19 }
20}
21
22impl<K, V, Q: ?Sized> core::ops::Index<&Q> for LookupMap<K, V>
23where
24 K: BorshSerialize + Ord + Borrow<Q>,
25 V: BorshSerialize + BorshDeserialize,
26
27 Q: BorshSerialize + ToOwned<Owned = K>,
28{
29 type Output = V;
30
31 fn index(&self, index: &Q) -> &Self::Output {
32 self.get(index)
33 .unwrap_or_else(|| crate::panic("does not exist"))
34 }
35}