macro_rules! embed_modules {
($($key:expr => $file:expr),* $(,)?) => { ... };
($($key:expr => @inline $content:expr),* $(,)?) => { ... };
}Expand description
Macro to create an embedded file system with compile-time included modules.
This macro simplifies the creation of an embedded file system by automatically
generating the phf_map and wrapping it in a FileSystemEmbedded.
§Example
embed_modules! {
"module_path" => "file_path",
"another_module" => "another_file",
...
}use hyperlight_js::SandboxBuilder;
use hyperlight_js::embed_modules;
let fs = embed_modules! {
"math.js" => "../tests/fixtures/math.js",
"strings.js" => "../tests/fixtures/strings.js",
};
let proto_js_sandbox = SandboxBuilder::new().build().unwrap();
let sandbox = proto_js_sandbox
.set_module_loader(fs)
.unwrap()
.load_runtime()
.unwrap();// With inline content: let fs = embed_modules! { “test.js” => @inline “console.log(‘test’);”, };
§Notes
- File paths are relative to the current file