From 04a78badc58c6b5cdc0f9ad9eb67e2dc91a9e78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sat, 20 Apr 2019 09:29:03 +0300 Subject: [PATCH] Implement Debug for JsFuture --- crates/futures/src/lib.rs | 7 +++++++ crates/futures/tests/tests.rs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/crates/futures/src/lib.rs b/crates/futures/src/lib.rs index aaab7611..62d5e88d 100644 --- a/crates/futures/src/lib.rs +++ b/crates/futures/src/lib.rs @@ -104,6 +104,7 @@ #![deny(missing_docs)] use std::cell::{Cell, RefCell}; +use std::fmt; use std::rc::Rc; use std::sync::Arc; @@ -128,6 +129,12 @@ pub struct JsFuture { callbacks: Option<(Closure, Closure)>, } +impl fmt::Debug for JsFuture { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "JsFuture {{ ... }}") + } +} + impl From for JsFuture { fn from(js: Promise) -> JsFuture { // Use the `then` method to schedule two callbacks, one for the diff --git a/crates/futures/tests/tests.rs b/crates/futures/tests/tests.rs index d8ea2674..2262d7ef 100755 --- a/crates/futures/tests/tests.rs +++ b/crates/futures/tests/tests.rs @@ -52,6 +52,13 @@ fn error_future_is_rejected_promise() -> impl Future }) } +#[wasm_bindgen_test] +fn debug_jsfuture() { + let p = js_sys::Promise::resolve(&JsValue::from(42)); + let f = JsFuture::from(p); + assert_eq!(&format!("{:?}", f), "JsFuture { ... }"); +} + #[wasm_bindgen] extern "C" { fn setTimeout(c: &Closure);