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
use itertools::Itertools;
use mime::Mime;
use std::collections::HashMap;
pub type LookupTable = HashMap<String, Vec<usize>>;
pub trait LookupTableFromTypes {
fn from_types<'a, I: Iterator<Item = &'a Mime>>(types: I, include_stars: bool) -> Self;
}
impl LookupTableFromTypes for LookupTable {
fn from_types<'a, I: Iterator<Item = &'a Mime>>(types: I, include_stars: bool) -> Self {
if include_stars {
types
.enumerate()
.flat_map(|(i, mime)| {
vec![
("*/*".to_owned(), i),
(format!("{}/*", mime.type_()), i),
(mime.essence_str().to_owned(), i),
]
.into_iter()
})
.into_group_map()
} else {
types
.enumerate()
.map(|(i, mime)| (mime.essence_str().to_owned(), i))
.into_group_map()
}
}
}