Debug a WebAssembly Module Written in Rust using console.log

Nik Graf
InstructorNik Graf
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 6 years ago

Having some kind of debugging tool in our belt is extremely useful before writing a lot of code. In this lesson we build a println!()-style syntax using JavaScript’s console.log to be able to log out values in Rust.

Instructor: [00:00] Before we write much more code, we will want to have some debugging tools in our belt. One simple but still effective tool for investigating our programs is logging.

[00:10] In JavaScript, the console log function is the way to log messages to the browser's developer tool console. Using Rust [inaudible] , we can import a reference to it. Using the Rust macro, we can provide a [inaudible] style syntax for console log, logging from Rust.

[00:33] In our run function, we now can use the log macro and log the side value to the console. We reload the page in our browser and can see the meaning of life is 42. Great, our macro worked.

Jack Hollis London
Jack Hollis London
~ 6 years ago

The extern "C" code block isn't in my ./crate/src/lib.rs file?

Nik Graf
Nik Grafinstructor
~ 6 years ago

@Jack the "C" is not mandatory as far as I know or what do you mean?

Markdown supported.
Become a member to join the discussionEnroll Today