MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / from_trusted_file

Method from_trusted_file

crates/wasmtime/src/runtime/module.rs:348–359  ·  view source on GitHub ↗
(engine: &Engine, file: impl AsRef<Path>)

Source from the content-addressed store, hash-verified

346 /// state of the file.
347 #[cfg(all(feature = "std", any(feature = "cranelift", feature = "winch")))]
348 pub unsafe fn from_trusted_file(engine: &Engine, file: impl AsRef<Path>) -> Result<Module> {
349 let open_file = open_file_for_mmap(file.as_ref())?;
350 let mmap = crate::runtime::vm::MmapVec::from_file(open_file)?;
351 if &mmap[0..4] == b"\x7fELF" {
352 let code = engine.load_code(mmap, ObjectKind::Module)?;
353 return Module::from_parts(engine, code, None);
354 }
355
356 crate::CodeBuilder::new(engine)
357 .wasm_binary_or_text(&mmap[..], Some(file.as_ref()))?
358 .compile_module()
359 }
360
361 /// Deserializes an in-memory compiled module previously created with
362 /// [`Module::serialize`] or [`Engine::precompile_module`].

Callers

nothing calls this directly

Calls 6

load_codeMethod · 0.80
compile_moduleMethod · 0.80
wasm_binary_or_textMethod · 0.80
open_file_for_mmapFunction · 0.50
newFunction · 0.50
as_refMethod · 0.45

Tested by

no test coverage detected