keymap: Simplified key state passing

There's no need to treat states as a shared resource before they are placed inside buttons.
This commit is contained in:
Dorota Czaplejewicz
2019-10-09 15:38:21 +00:00
parent 9cd439767e
commit dc2bc46167
3 changed files with 31 additions and 9 deletions

View File

@ -1,3 +1,8 @@
/*! Assorted helpers */
use std::collections::HashMap;
use std::iter::FromIterator;
pub mod c {
use std::cell::RefCell;
use std::ffi::{ CStr, CString };
@ -101,3 +106,13 @@ pub mod c {
}
}
}
pub fn hash_map_map<K, V, F, K1, V1>(map: HashMap<K, V>, mut f: F)
-> HashMap<K1, V1>
where F: FnMut(K, V) -> (K1, V1),
K1: std::cmp::Eq + std::hash::Hash
{
HashMap::from_iter(
map.into_iter().map(|(key, value)| f(key, value))
)
}