mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-12 13:57:14 +00:00
Merge pull request #1408 from samcday/impl-debug-on-closure
Implement Debug on Closures
This commit is contained in:
commit
c5f18b6099
@ -4,6 +4,7 @@
|
|||||||
//! closures" from Rust to JS. Some more details can be found on the `Closure`
|
//! closures" from Rust to JS. Some more details can be found on the `Closure`
|
||||||
//! type itself.
|
//! type itself.
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
use std::marker::Unsize;
|
use std::marker::Unsize;
|
||||||
use std::mem::{self, ManuallyDrop};
|
use std::mem::{self, ManuallyDrop};
|
||||||
@ -489,6 +490,15 @@ fn _check() {
|
|||||||
_assert::<&Closure<FnMut() -> String>>();
|
_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>
|
impl<T> Drop for Closure<T>
|
||||||
where
|
where
|
||||||
T: ?Sized,
|
T: ?Sized,
|
||||||
|
@ -107,6 +107,12 @@ fn cannot_reuse() {
|
|||||||
assert!(cannot_reuse_call_again().is_err());
|
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]
|
#[wasm_bindgen_test]
|
||||||
fn long_lived() {
|
fn long_lived() {
|
||||||
let hit = Rc::new(Cell::new(false));
|
let hit = Rc::new(Cell::new(false));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user