#[repr(C)]pub struct JsModuleDef {
pub name: String,
pub declared: Vec<String>,
pub values: Vec<(String, Value)>,
pub init: ModuleInitFunc,
pub private: Option<Value>,
}Expand description
JSModuleDef: a C module’s definition, as JS_NewCModule answers it.
The C side only passes it back, so the fields are ours — but it has to be a real
allocation with a stable address, because JS_AddModuleExport is called with the same
pointer the init function was given. It is repr(C) for the same reason: nothing on the
C side looks inside, and a plain Rust layout is all it needs.
Fields§
§name: StringThe module name, as JS_NewCModule received it.
declared: Vec<String>The exports added with JS_AddModuleExport/JS_AddModuleExportList.
values: Vec<(String, Value)>The values set with JS_SetModuleExport.
Engine values, not JSValues: JS_SetModuleExport consumes the reference it is
given (as the C API says it does), so what is kept is the engine’s own handle. That
keeps the module definition out of the reference-counting business entirely, and a
definition therefore needs no Drop.
init: ModuleInitFuncThe function that fills the exports in, run when the module is instantiated.
private: Option<Value>JS_SetModulePrivateValue’s value, which a host uses to reach its own data from a
module’s callbacks.