Skip to content

SOS: macro_rules log not working. need a correct example #116

Open
@aqrun

Description

@aqrun

From chapter 4.6 Debugging

in the lib.rs file added:

#[macro_export]
macro_rules! log {
    ( $( &t:tt )* ) => {
        web_sys::console::log_1(&format!( &( &t )* ).into());
    }
}

log!("test data {}", 1);

then run wasm-pack build it prints:

error: no rules expected the token `"test data {}"`
  --> src/lib.rs:16:6
   |
10 | macro_rules! log {
   | ---------------- when calling this macro
...
16 | log!("test data {}", 1);
   |      ^^^^^^^^^^^^^^ no rules expected this token in macro call
   |
   = note: while trying to match sequence start

error: could not compile `wasm-game-of-life` (lib) due to previous error

could anyone give a correct code. thanks!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions