Merge pull request #1408 from samcday/impl-debug-on-closure

Implement Debug on Closures
This commit is contained in:
Alex Crichton 2019-03-29 07:32:11 -05:00 committed by GitHub
commit c5f18b6099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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));