Skip to content

Commit 056ae8d

Browse files
authored
Enable js macro in more context
Once in a lifetime, situation does not allow for `let` keyword in certain contexts (example below, not the best but still proves the point). There is no apparent downside to this extra wrap in `{}`. Alternatively, `let` can be safely remove instead of this. This seemed so minor of a change that I did not bother with testing, reading any docs. I just saw no comments around the macro so I assumed it's safe to modify and write about. Sorry! ```rust error: expected expression, found `let` statement --> src/x.rs:185:23 | 185 | this1.and_then(|i| js!(o["this1"] = i)); | ^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions = note: this error originates in the macro `js` (in Nightly builds, run with -Z macro-backtrace for more info) ```
1 parent 1d6cdc8 commit 056ae8d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/utils/js.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ macro_rules! js {
44
wasm_bindgen::JsValue::from($attr).js_in($($obj)*)
55
};
66
($obj:ident[$attr:literal] = $($val:tt)*) => {
7-
let _ = js_sys::Reflect::set(&$obj, &$attr.into(), &($($val)*).into());
7+
{
8+
let _ = js_sys::Reflect::set(&$obj, &$attr.into(), &($($val)*).into());
9+
}
810
};
911
($obj:ident[$attr:literal]) => {
1012
js_sys::Reflect::get(&$obj, &$attr.into())
@@ -16,5 +18,4 @@ macro_rules! js_fut {
1618
($($obj:tt)*) => {
1719
wasm_bindgen_futures::JsFuture::from($($obj)*)
1820
};
19-
2021
}

0 commit comments

Comments
 (0)