From 542d970dd660b97596e1d15d8f34b138b875b786 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Sun, 1 Dec 2024 22:40:57 +0100 Subject: [PATCH] add .wat support to Module::new --- crates/wasmi/src/module/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/wasmi/src/module/mod.rs b/crates/wasmi/src/module/mod.rs index 4733cb4703..028dbc8ad3 100644 --- a/crates/wasmi/src/module/mod.rs +++ b/crates/wasmi/src/module/mod.rs @@ -201,7 +201,9 @@ impl Module { /// /// # Note /// - /// This parses, validates and translates the buffered Wasm bytecode. + /// - This parses, validates and translates the buffered Wasm bytecode. + /// - The `wasm` may be encoded as WebAssembly binary (`.wasm`) or as + /// WebAssembly text format (`.wat`). /// /// # Errors /// @@ -211,7 +213,10 @@ impl Module { /// - If Wasmi cannot translate the Wasm bytecode. /// /// [`Config`]: crate::Config - pub fn new(engine: &Engine, wasm: &[u8]) -> Result { + pub fn new(engine: &Engine, wasm: impl AsRef<[u8]>) -> Result { + let wasm = wasm.as_ref(); + #[cfg(feature = "wat")] + let wasm = &wat::parse_bytes(wasm)?[..]; ModuleParser::new(engine).parse_buffered(wasm) }