Debug impl, is it possible to get file and line number of Box<dyn Fn()>?

I have a struct holds what usually is a closure like this. I would like to give some sensible debug impl as this closure is user supplied.

So far the only thing I can think of is forcing a new function for creation and storing backtrace information, but it's not what I hope to do.

You can use line!() and file!() to get the current line/file; you'd need to make user creation of your struct through a macro that calls these macros, though, to get the correct info (and that'd only point to the line where the struct is created.)

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.