Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing JsValues directly to console.log(...)? #9

Open
anp opened this issue Aug 23, 2020 · 1 comment
Open

Support passing JsValues directly to console.log(...)? #9

anp opened this issue Aug 23, 2020 · 1 comment

Comments

@anp
Copy link

anp commented Aug 23, 2020

The use case I have is pretty-printing wasm_bindgen::JsValues. Right now I always make a string by walking the object tree and passing that to tracing. If tokio-rs/tracing#905 were to happen, I think this crate could define an interface to pass nested values directly through to the backend without needing to teach the Value trait about all of the details of the APIs.

I'm not sure exactly what that would look like but I thought I'd gauge interest.

@colelawrence
Copy link
Member

Thanks for sharing the idea. It sounds like it's not too fun of a problem to solve.

I can say that we have not needed this functionality, yet since our usage from the web side is as complex as JSON-RPC from web to wasm & back. So, in our use-case, we don't really touch JsValues.

Perhaps this is what you were describing, here, but a common answer to problems like this is to try using a wrapper type like struct JsValueTracing(wasm_bindgen::JsValue); and impl tracing::Value for JsValueTracing.

Then, if it's common enough of a need, I'd end up putting a fn jt(js_value: wasm_bindgen::JsValue) -> JsValueTracing into my project prelude to be accessed everywhere easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants