| 94 | } |
| 95 | |
| 96 | fn load_plugins(state: &mut CalculatorState, plugins_dir: &Path) -> wasmtime::Result<()> { |
| 97 | let engine = Engine::default(); |
| 98 | let linker: Linker<()> = Linker::new(&engine); |
| 99 | |
| 100 | if !plugins_dir.is_dir() { |
| 101 | wasmtime::bail!("plugins directory does not exist"); |
| 102 | } |
| 103 | |
| 104 | for entry in fs::read_dir(plugins_dir)? { |
| 105 | let path = entry?.path(); |
| 106 | if path.is_file() && path.extension().and_then(OsStr::to_str) == Some("wasm") { |
| 107 | load_plugin(state, &engine, &linker, path)?; |
| 108 | } |
| 109 | } |
| 110 | Ok(()) |
| 111 | } |
| 112 | |
| 113 | #[derive(Parser)] |
| 114 | #[command(name = "calculator-host", version = env!("CARGO_PKG_VERSION"))] |