Skip to content

Commit d47dc31

Browse files
committed
Improve macro
1 parent 9c97526 commit d47dc31

File tree

2 files changed

+4
-29
lines changed

2 files changed

+4
-29
lines changed

src/lib.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,3 @@ mod definition;
1414
mod loader;
1515
mod macros;
1616
mod wrapper;
17-
18-
#[cfg(test)]
19-
mod tests {
20-
use rquickjs::{
21-
async_with, class::Trace, context::EvalOptions, AsyncContext, AsyncRuntime, CatchResultExt,
22-
JsLifetime, Object, Result, Value,
23-
};
24-
25-
use super::*;
26-
27-
struct Example;
28-
impl ModuleDefExt for Example {
29-
type Implementation = GlobalsOnly;
30-
31-
fn implementation() -> &'static Self::Implementation {
32-
&GlobalsOnly
33-
}
34-
35-
fn options(self) {}
36-
}
37-
38-
struct Example2;
39-
globals_only_module!(Example2, |globals| {
40-
// Custom globals initialization code here
41-
Ok(())
42-
});
43-
}

src/macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#[macro_export]
22
macro_rules! globals_only_module {
3-
($name:ident, $globals_impl:expr) => {
3+
($name:ident, |$globals:ident| { $($t:tt)* }) => {
44
impl ModuleDefExt for $name {
55
type Implementation = GlobalsOnly;
66

77
fn globals(globals: &Object<'_>, _options: &()) -> Result<()> {
8-
$globals_impl(globals)
8+
(|$globals: &Object<'_>| {
9+
$($t)*
10+
})(globals)
911
}
1012

1113
fn implementation() -> &'static Self::Implementation {

0 commit comments

Comments
 (0)