1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::collections::HashMap;
pub mod itunes;
pub mod dublincore;
pub type ExtensionMap = HashMap<String, HashMap<String, Vec<Extension>>>;
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Extension {
pub name: String,
pub value: Option<String>,
pub attrs: HashMap<String, String>,
pub children: HashMap<String, Vec<Extension>>,
}
pub fn get_extension_value<'a>(map: &'a HashMap<String, Vec<Extension>>,
key: &str)
-> Option<&'a str> {
map.get(key).and_then(|v| v.first()).and_then(|ext| ext.value.as_ref()).map(|s| s.as_str())
}
pub fn remove_extension_value(map: &mut HashMap<String, Vec<Extension>>,
key: &str)
-> Option<String> {
map.remove(key).map(|mut v| v.remove(0)).and_then(|ext| ext.value)
}
pub fn get_extension_values<'a>(map: &'a HashMap<String, Vec<Extension>>,
key: &str)
-> Option<Vec<&'a str>> {
map.get(key).map(|v| {
v.iter().filter_map(|ext| ext.value.as_ref().map(|s| s.as_str())).collect::<Vec<_>>()
})
}
pub fn remove_extension_values(map: &mut HashMap<String, Vec<Extension>>,
key: &str)
-> Option<Vec<String>> {
map.remove(key).map(|v| v.into_iter().filter_map(|ext| ext.value).collect::<Vec<_>>())
}