Attribute Macro rquickjs_macro::embed[][src]

#[embed]

An attribute to convert scripts modules into builtins

Supported attributes

AttributeDescription
ident = "MyModule"The name of target unit struct to export
public, public = "self/super/crate"Makes the target unit struct visible
path = "search-path"Add a paths where modules can be found
name = "module-name"The name of module to embed
perfectUse perfect hash map for embedded modules (feature = "phf")
crate = "rquickjs"Allows rename rquickjs crate

Examples


#[embed(path = "../examples/module-loader")]
mod script_module {}

let rt = Runtime::new().unwrap();
let ctx = Context::full(&rt).unwrap();

rt.set_loader(SCRIPT_MODULE, SCRIPT_MODULE);

ctx.with(|ctx| {
    ctx.compile("script", r#"
        import { n, s, f } from "script_module";
    "#).unwrap();
});