neovim-gtk/src/value.rs
2017-07-08 14:02:56 +03:00

21 lines
562 B
Rust

use std::collections::HashMap;
use neovim_lib::Value;
pub trait ValueMapExt {
fn to_attrs_map(&self) -> Result<HashMap<&str, Value>, String>;
}
impl ValueMapExt for Vec<(Value, Value)> {
fn to_attrs_map(&self) -> Result<HashMap<&str, Value>, String> {
self.iter()
.map(|p| {
p.0
.as_str()
.ok_or("Can't convert map key to string".to_owned())
.map(|key| (key, p.1.clone()))
})
.collect::<Result<HashMap<&str, Value>, String>>()
}
}