1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use ActionMapper;
use error::*;
use libflo_module::ModuleMapper;
use serialization::ActionMapperSerde;
use std::collections::HashMap;

pub struct ExtActionMapper<'a, 'b> {
    action_mapper: &'a ActionMapper,
    module_mapper: &'b ModuleMapper,
}

impl <'a, 'b> ExtActionMapper<'a, 'b> {
    pub fn new(
        action_mapper: &'a ActionMapper,
        module_mapper: &'b ModuleMapper,
    ) -> Self {
        ExtActionMapper {
            action_mapper: action_mapper,
            module_mapper: module_mapper
        }
    }

    pub fn get<TStr: AsRef<str>>(&self, module_id: usize, action_name: TStr) -> Result<usize> {
        self.action_mapper.get(module_id, action_name).map_err(|err| err.into())
    }

    pub fn get_by_module_name<TStr0: AsRef<str>, TStr1: AsRef<str>>(&self, module_name: TStr0, action_name: TStr1) -> Result<usize> {
        let module_id = self.module_mapper.get(module_name)?;
        self.get(module_id, action_name)
    }

    pub fn get_raw_map(&self) -> &Vec<Option<HashMap<String, usize>>> {
        self.action_mapper.get_raw_map()
    }

    pub fn make_serde(&self) -> ActionMapperSerde {
        self.action_mapper.make_serde()
    }
}