use error::*; use serialization::ActionMapperSerde; use std::collections::HashMap; pub struct ActionMapper { action_map: Vec>>, } impl ActionMapper { pub fn new( action_map: Vec>>, ) -> Self { ActionMapper { action_map: action_map, } } pub fn get(&self, module_id: usize, action_name: TStr) -> Result where TStr: AsRef { let action_name = action_name.as_ref(); match self.action_map.get(module_id) { Some(&Some(ref some)) => { match some.get(action_name) { Some(some) => Ok(some.clone()), None => Err(ErrorKind::ActionNotFoundInMap(module_id, action_name.to_string()).into()) } }, None | Some(&None) => Err(ErrorKind::ActionNotFoundInMap(module_id, action_name.to_string()).into()), } } pub fn get_raw_map(&self) -> &Vec>> { &self.action_map } pub fn make_serde(&self) -> ActionMapperSerde { ActionMapperSerde::new(&self.action_map) } }