1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#[doc(hidden)] #[macro_export] macro_rules! __internal_console_unsafe { ( $name:ident ) => {{ $crate::js! { @(no_return) console.$name(); } () }}; ( $name:ident, $( $args:expr ),* ) => {{ $crate::js! { @(no_return) console.$name( $( @{$args} ),* ); } () }}; } /// Calls methods on the JavaScript `console` object. /// /// This should **only** be used for debugging purposes, its behavior is /// **not** standardized: it **will** vary with different browsers /// and Node.js. /// /// The first argument is the name of the `console` method. /// /// The remaining arguments can be anything which can be sent to JavaScript, /// and they do not need to be the same type. /// /// If you want to print things to the console in a standardized way, use /// [`println!`](https://doc.rust-lang.org/std/macro.println.html) instead. /// /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/console) /// /// # Examples /// /// ## log /// /// Print a newline: /// /// ```rust /// console!(log, ""); /// ``` /// /// Print one value: /// /// ```rust /// console!(log, "Hello world!"); /// ``` /// /// Print more than one value: /// /// ```rust /// console!(log, 1, "test", vec![2, 3]); /// ``` /// /// Use [string substitution](https://developer.mozilla.org/en-US/docs/Web/API/console#Using_string_substitutions) to control how the values are printed: /// /// ```rust /// console!(log, "foo: %s bar: %s", vec![1, 2], vec![3, 4]); /// ``` /// /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/Console/log) /// /// ## error /// /// This is exactly the same as `log`, except it prints an error message rather than a normal message. /// /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/Console/error) #[macro_export] macro_rules! console { ( log, $( $args:expr ),+ ) => { $crate::__internal_console_unsafe!( log, $( $args ),+ ) }; ( error, $( $args:expr ),+ ) => { $crate::__internal_console_unsafe!( error, $( $args ),+ ) }; }