I have some code like this:
type MyFn = Box<Fn(usize) -> bool>;
fn main() {
let my_fn: MyFn = Box::new(|x: usize| x > 10);
dbg!(my_fn);
}
This doesn't compile because MyFn
doesn't implement std::fmt::Debug
. That's reasonable, so what if I try to implement it for MyFn
?
It fails saying:
conflicting implementations of trait std::fmt::Debug
for type std::boxed::Box<(dyn std::ops::Fn(usize) -> bool + 'static)>
As well as:
only traits defined in the current crate can be implemented for arbitrary types
How can I implement Debug
and other traits for MyFn
?