Impl Debug for multi-variant enum

pub enum FnCast {
    FnReturnContext(fn(Context) -> Context),
    FnReturnJSON(fn(Context) -> Value),
    FnPush(for<'a> fn(SomeType, &mut Another)),

the standard derive macro works for all but FnPush. How do I implement debug here?

You can implement Debug for a wrapper type around fn(SomeType, &mut Another), like this:

pub struct DebugFn(pub fn(SomeType, &mut Another));

impl fmt::Debug for DebugFn {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:p}", &self.0)
1 Like

I dont like the indirection... but it works. TY :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.