nvim_gtk/
value.rs

1use std::collections::HashMap;
2use neovim_lib::Value;
3
4pub trait ValueMapExt {
5    fn to_attrs_map(&self) -> Result<HashMap<&str, &Value>, String>;
6
7    fn to_attrs_map_report(&self) -> Option<HashMap<&str, &Value>>;
8}
9
10impl ValueMapExt for Vec<(Value, Value)> {
11    fn to_attrs_map(&self) -> Result<HashMap<&str, &Value>, String> {
12        self.iter()
13            .map(|p| {
14                p.0
15                    .as_str()
16                    .ok_or_else(|| "Can't convert map key to string".to_owned())
17                    .map(|key| (key, &p.1))
18            })
19            .collect::<Result<HashMap<&str, &Value>, String>>()
20
21    }
22
23    fn to_attrs_map_report(&self) -> Option<HashMap<&str, &Value>> {
24        match self.to_attrs_map() {
25            Err(e) => {
26                error!("{}", e);
27                None
28            }
29            Ok(m) => Some(m),
30        }
31    }
32}