(index: usize, ty: WasmType, value: &str)
| 12 | } |
| 13 | |
| 14 | fn parse_arg(index: usize, ty: WasmType, value: &str) -> Result<WasmValue> { |
| 15 | let parsed = match ty { |
| 16 | WasmType::I32 => value.parse::<i32>().map(WasmValue::from).map_err(|e| format_error(index, ty, value, e))?, |
| 17 | WasmType::I64 => value.parse::<i64>().map(WasmValue::from).map_err(|e| format_error(index, ty, value, e))?, |
| 18 | WasmType::F32 => value.parse::<f32>().map(WasmValue::from).map_err(|e| format_error(index, ty, value, e))?, |
| 19 | WasmType::F64 => value.parse::<f64>().map(WasmValue::from).map_err(|e| format_error(index, ty, value, e))?, |
| 20 | WasmType::V128 => value |
| 21 | .parse::<i128>() |
| 22 | .map(|v| WasmValue::V128(v.to_le_bytes())) |
| 23 | .map_err(|e| format_error(index, ty, value, e))?, |
| 24 | WasmType::RefFunc | WasmType::RefExtern => { |
| 25 | bail!( |
| 26 | "unsupported CLI argument type at position {}: {}; use the embedding API for reference values", |
| 27 | index + 1, |
| 28 | format_wasm_type(ty) |
| 29 | ) |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | Ok(parsed) |
| 34 | } |
| 35 | |
| 36 | fn format_error(index: usize, ty: WasmType, value: &str, error: impl core::fmt::Display) -> eyre::Report { |
| 37 | eyre::eyre!("failed to parse argument {} as {} from `{value}`: {error}", index + 1, format_wasm_type(ty)) |
no test coverage detected