ibc_testkit/testapp/ibc/core/router/
context.rs

1use alloc::sync::Arc;
2
3use ibc::core::host::types::identifiers::PortId;
4use ibc::core::router::module::Module;
5use ibc::core::router::router::Router;
6use ibc::core::router::types::module::ModuleId;
7
8use super::types::MockRouter;
9
10impl Router for MockRouter {
11    fn get_route(&self, module_id: &ModuleId) -> Option<&dyn Module> {
12        self.router.get(module_id).map(Arc::as_ref)
13    }
14    fn get_route_mut(&mut self, module_id: &ModuleId) -> Option<&mut dyn Module> {
15        // NOTE: The following:
16
17        // self.router.get_mut(module_id).and_then(Arc::get_mut)
18
19        // doesn't work due to a compiler bug. So we expand it out manually.
20
21        match self.router.get_mut(module_id) {
22            Some(arc_mod) => match Arc::get_mut(arc_mod) {
23                Some(m) => Some(m),
24                None => None,
25            },
26            None => None,
27        }
28    }
29
30    fn lookup_module(&self, port_id: &PortId) -> Option<ModuleId> {
31        self.port_to_module.get(port_id).cloned()
32    }
33}