Hello, I'm trying to implement the From trait for a closure:
pub enum Arg {
Predicate(Box<dyn Fn() -> bool>)
}
impl From<Box<dyn Fn() -> bool>> for Arg {
fn from(predicate: Box<dyn Fn() -> bool>) -> Self {
Arg::Predicate(predicate)
}
}
fn main() {
Arg::from(Box::new(|| true));
}
Which produce the following error:
error[E0277]: the trait bound `Arg: From<Box<[closure@src/main.rs:13:24: 13:31]>>` is not satisfied
--> src/main.rs:13:5
|
13 | Arg::from(Box::new(|| true));
| ^^^^^^^^^ the trait `From<Box<[closure@src/main.rs:13:24: 13:31]>>` is not implemented for `Arg`
|
= help: the following implementations were found:
<Arg as From<Box<(dyn Fn() -> bool + 'static)>>>
= note: required by `from`
Also, if possible I would like the Box
in the main to not appear.
Thanks for the help.