Stdweb println!


Short Question: Is there a way to get println! to work with stdweb ?

Long Question: Right now, to print stuff in stdweb, I’m doing:

let msg = format!(...);
js! { console.log ( @{ msg }); }

I would prefer to just use println! instead.

Is there a way to have stdweb display println! output?




You could always just redefine println:

macro_rules! println {
    ($($tt:tt)*) => {{
        let msg = format!($($tt)*);
        js! { console.log(@{ msg }) }



Thanks for the macro. However this doesn’t quite work if I am trying to println-debug a shared library that runs on both native & wasm32.

This now forces the shared library to pull in stdweb to get the js! macro.



Use conditional compilation via #[cfg(target = "wasm32-unknown-unknown")]



Doesn’t println! already work with stdweb? The docs seem to imply as much:*/stdweb/macro.console.html

If you want to print things to the console in a standardized way, use println! instead.

And the examples also use println!

1 Like


@parasyte : I agree the docs imply println! “just works.”

I must be doing something wrong as it is definitely not p;rinting for me right now.



Maybe it’s time to create a new issue on their github project? I went through the issues list and didn’t see anything relevant.

1 Like



You’re right – If I can produce a minimal failure case, I will post to github.

Println! is definitely not working in my 2k+ LOC codebase, but I have not created a minimal fail case yet.

1 Like


Hi there,

I know this may be a bit late, but if you are working on 2018 edition and just using

use stdweb;

Or what have you, that is your issue. Even though the Rust docs say that 99% cases can remove “extern crate”:, see here. If you want to use any of the macros, you must use

extern crate stdweb;


I guess you mean

extern crate stdweb;