poke_data/data/
linkable.rs1use crate::data::link_context::LinkContext;
2use std::collections::HashMap;
3use std::hash::Hash;
4
5pub trait Linkable {
6 type Linked;
7 fn link(&self, context: &LinkContext) -> Self::Linked;
8}
9
10impl<K, V> Linkable for HashMap<K, V>
11where
12 K: Eq + Hash + Copy,
13 V: Linkable,
14{
15 type Linked = HashMap<K, V::Linked>;
16
17 fn link(&self, context: &LinkContext) -> Self::Linked {
18 self.iter()
19 .map(|(id, item)| (*id, item.link(context)))
20 .collect()
21 }
22}
23
24impl<V> Linkable for Vec<V>
25where
26 V: Linkable,
27{
28 type Linked = Vec<V::Linked>;
29 fn link(&self, context: &LinkContext) -> Self::Linked {
30 self.iter().map(|item| item.link(context)).collect()
31 }
32}