News for hackers. Stuff that matters.
Re:C++ vs. Rust Build Times by Rusky on Friday January 06, 2023 @01:00PM (#34278412)
> Can you give an example or provide a citation to this?

It would look something like this:

    trait MyOperation {
        fn run(&mut self, a: T, b: U, c: V) -> R;
    }
    impl<F> MyOperation for F where F: FnMut(T, U, V) -> R {
        fn run(&mut self, a: T, b: U, c: V) -> R { self(a, b, c) }
    }

    fn my_api<F: MyOperation>(f: F) { ... f.run(a, b, c) ... }

    struct MyFunctor { ... }
    impl MyOperation for MyFunctor { ... }
    my_api(MyFunctor { ... });
That is, when defining `my_api` and you would like to accept both lambdas and functors, instead of using a `Fn` trait bound directly, use a more specific trait which has a blanket impl for lambdas.

There are no comments on this comment yet.