(local_key: u64, cfg: &LoaderConfig)
| 47 | static ONCE_LOAD_FROM_SCOPE: Once = Once::new(); |
| 48 | |
| 49 | pub(crate) fn load(local_key: u64, cfg: &LoaderConfig) -> Result<()> { |
| 50 | let loader = <Box<dyn Loader>>::registry_global().get(&cfg.ty).unwrap(); |
| 51 | ONCE_LOAD_FROM_SCOPE.call_once(|| { |
| 52 | for plugin in loader |
| 53 | .load_from_scope(local_key) |
| 54 | .expect("cannot load plugins from current scope") |
| 55 | { |
| 56 | plugin.submit(); |
| 57 | } |
| 58 | }); |
| 59 | |
| 60 | if let Some(plugin_path) = &cfg.plugin_path { |
| 61 | for entry in fs::read_dir(&plugin_path)? { |
| 62 | let entry = entry?; |
| 63 | let pathbuf = entry.path(); |
| 64 | let path: &Path = pathbuf.as_ref(); |
| 65 | if let Some(path) = cfg.ty.check(path) { |
| 66 | for plugin in loader.load_from_file( |
| 67 | local_key, |
| 68 | cfg.module_path.as_ref().map(|x| x.as_ref()), |
| 69 | path.as_path(), |
| 70 | )? { |
| 71 | plugin.submit(); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | Ok(()) |
| 78 | } |
| 79 | |
| 80 | impl PluginType { |
| 81 | fn check(&self, path: &Path) -> Option<PathBuf> { |
no test coverage detected