Implement Debug on Closures

resolves #1387
This commit is contained in:
Sam Day 2019-03-29 09:07:42 +01:00
parent 30b258515d
commit 1914bba0be
2 changed files with 16 additions and 0 deletions

View File

@ -4,6 +4,7 @@
//! closures" from Rust to JS. Some more details can be found on the `Closure`
//! type itself.
use std::fmt;
#[cfg(feature = "nightly")]
use std::marker::Unsize;
use std::mem::{self, ManuallyDrop};
@ -489,6 +490,15 @@ fn _check() {
_assert::<&Closure<FnMut() -> String>>();
}
impl<T> fmt::Debug for Closure<T>
where
T: ?Sized,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Closure {{ ... }}")
}
}
impl<T> Drop for Closure<T>
where
T: ?Sized,

View File

@ -107,6 +107,12 @@ fn cannot_reuse() {
assert!(cannot_reuse_call_again().is_err());
}
#[wasm_bindgen_test]
fn debug() {
let closure = Closure::wrap(Box::new(|| {}) as Box<FnMut()>);
assert_eq!(&format!("{:?}", closure), "Closure { ... }");
}
#[wasm_bindgen_test]
fn long_lived() {
let hit = Rc::new(Cell::new(false));