use std::collections::BTreeMap; #[derive(Clone)] pub struct StringyMap(BTreeMap); impl StringyMap where K: ToString, { pub fn new() -> Self { StringyMap(BTreeMap::new()) } pub fn insert(&mut self, k: K, v: V) -> Option { let s = k.to_string(); self.0.insert(s, (k, v)).map(|(_, v)| v) } pub fn remove(&mut self, k: &K) -> Option { let s = k.to_string(); self.0.remove(&s).map(|(_, v)| v) } pub fn iter(&self) -> impl Iterator { self.0.values() } pub fn keys(&self) -> impl Iterator { self.0.values().map(|(k, _)| k) } } impl From> for StringyMap where OK: Into, OV: Into, K: ToString, { fn from(vec: Vec<(OK, OV)>) -> Self { let mut out = Self::new(); for (key, value) in vec { out.insert(key.into(), value.into()); } out } }