uap-rust 0.0.4

User agent parser library for Rust based on the ua-parser project
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use yaml_rust::{Yaml};

pub fn from_map<'a>(map: &'a Yaml, key: &str) -> Option<&'a Yaml> {
    map.as_hash().and_then(|h| h.get(&Yaml::String(key.to_string())))
}

pub fn string_from_map(map: &Yaml, key: &str) -> Option<String> {
    from_map(map, key).and_then(|y| y.as_str()).map(|s| s.to_string())
}

pub fn filter_map_over_arr<T,F>(arr: &Yaml, f: F) -> Vec<T> where
F: Fn(&Yaml) -> Option<T>{
    arr.as_vec().map(|a| a.iter().filter_map(f).collect()).unwrap_or(Vec::new())
}