1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Debug a WebAssembly Module Written in Rust using console.log

    Nik GrafNik Graf
    webpackwebpack
    rustRust
    javascriptJavaScript

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 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.

    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.

    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.

    Discuss

    Discuss