Skip to content

Commit 04a78ba

Browse files
committed
Implement Debug for JsFuture
1 parent 7decb13 commit 04a78ba

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

crates/futures/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#![deny(missing_docs)]
105105

106106
use std::cell::{Cell, RefCell};
107+
use std::fmt;
107108
use std::rc::Rc;
108109
use std::sync::Arc;
109110

@@ -128,6 +129,12 @@ pub struct JsFuture {
128129
callbacks: Option<(Closure<FnMut(JsValue)>, Closure<FnMut(JsValue)>)>,
129130
}
130131

132+
impl fmt::Debug for JsFuture {
133+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
134+
write!(f, "JsFuture {{ ... }}")
135+
}
136+
}
137+
131138
impl From<Promise> for JsFuture {
132139
fn from(js: Promise) -> JsFuture {
133140
// Use the `then` method to schedule two callbacks, one for the

crates/futures/tests/tests.rs

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ fn error_future_is_rejected_promise() -> impl Future<Item = (), Error = JsValue>
5252
})
5353
}
5454

55+
#[wasm_bindgen_test]
56+
fn debug_jsfuture() {
57+
let p = js_sys::Promise::resolve(&JsValue::from(42));
58+
let f = JsFuture::from(p);
59+
assert_eq!(&format!("{:?}", f), "JsFuture { ... }");
60+
}
61+
5562
#[wasm_bindgen]
5663
extern "C" {
5764
fn setTimeout(c: &Closure<FnMut()>);

0 commit comments

Comments
 (0)