Skip to content

Closure should impl Debug #1387

@Pauan

Description

@Pauan

Motivation

When implementing rustwasm/gloo#30, I created this type:

pub struct EventListener<'a> {
    target: EventTarget,
    kind: &'a str,
    callback: Option<Closure<FnMut(Event)>>,
}

I would really like to just slap a #[derive(Debug)] and call it a day, but Closure doesn't impl Debug, so I have to do this instead:

impl<'a> std::fmt::Debug for EventListener<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.debug_struct("EventListener")
            .field("target", &self.target)
            .field("kind", &self.kind)
            .field("callback", &"Closure { ... }")
            .finish()
    }
}

Proposed Solution

I propose that Closure should provide a Debug impl, which essentially just outputs Closure { ... } (or similar).

Alternatives

Maybe the Debug impl should expose more information? For example, it could call .toString() on the JS function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueThis is a good issue for people who have never contributed to wasm-bindgen before

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions