From fbc37f48f72a84c4ef0c45bb521a938fddc17cb4 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Tue, 15 Sep 2020 13:20:37 +0200 Subject: [PATCH] Add examples to README.md --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d167161..2031764 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,54 @@ weblog is a crate that defines a set of macros for calling `console.log()`, `console.error()` and other members of the browser's console API when targeting Wasm. -### Features +## Features * Supports `web-sys` and `stdweb` backends with an identical public API * Support for variadic arguments on all calls * No stringification before sending to the browser - log entire objects and use the full introspective debugging power of the browser console. +## Examples + +A simple example. + +```rust +console_log!("Hello world!"); +``` + +Passing multiple arguments is fine too. + +```rust +console_log!("Foo", "bar", "baz"); +``` + +All of the common browser log levels are supported. + +```rust +console_debug!("Just testing..."); +console_warn!("...but then..."); +console_error!("...something bad happened."); +``` + +It's possible to send more than just strings or `&str`s: + +```rust +console_log!( + "&str", + "string".to_string(), + 1, + 2.0, + 3f32, + true, + false +); +``` + +When using `web-sys` crate the macros accept any value that implements the `Into` trait. See [JsValue](https://rustwasm.github.io/wasm-bindgen/api/wasm_bindgen/struct.JsValue.html) for +more details. + +No stringification is performed on the Rust side - so objects will be fully introspectable in the browser's console! + + ## Usage ```toml