I have an interface that I want to make callable like function. I don't need this to be templated on Args and Output like the Fn trait, since I want to define what types the args and return type will be. When I attempt this my code doesn't compile:
#![allow(unused)]
#![feature(unboxed_closures, fn_traits)]
type ActionArgs = (i32, bool);
pub trait Action: Fn(ActionArgs) -> bool {
extern "rust-call" fn call(&self, args: ActionArgs) -> bool;
}
struct Concrete {}
impl Action for Concrete {
extern "rust-call" fn call(&self, args: ActionArgs) -> bool {
args.0 == 2 && args.1
}
}
fn main() {
let c = Concrete{};
c((2, true));
}
This results in (on rust playground with nightly compiler):
error[E0277]: expected a `Fn<((i32, bool),)>` closure, found `Concrete`
--> src/main.rs:12:6
|
6 | pub trait Action: Fn(ActionArgs) -> bool {
| ---------------------- required by this bound in `Action`
...
12 | impl Action for Concrete {
| ^^^^^^ expected an `Fn<((i32, bool),)>` closure, found `Concrete`
|
= help: the trait `Fn<((i32, bool),)>` is not implemented for `Concrete`
error: aborting due to previous error
I have tried following other questions such as this, but with no success.