Skip to main content

fast_down_gui/utils/
header.rs

1use std::collections::HashMap;
2
3pub fn parse_header(input: &str) -> impl Iterator<Item = (&str, &str)> {
4    input
5        .lines()
6        .map(|s| s.splitn(2, ":").map(|s| s.trim()))
7        .map(|mut iter| (iter.next(), iter.next()))
8        .filter_map(|e| match e {
9            (None, None) => None,
10            (None, Some(_)) => None,
11            (Some(key), None) => Some((key, "")),
12            (Some(key), Some(value)) => Some((key, value)),
13        })
14}
15
16pub fn parse_header_hashmap(input: &str) -> HashMap<String, String> {
17    parse_header(input)
18        .map(|(k, v)| (k.to_string(), v.to_string()))
19        .collect()
20}