TL;DR
Is there any way I can implelement a trait for a closure, without using auto trait feature? Something like this:
let lambda = || {};
impl Foo for type_of(lambda) {}
What I have come across
Inspired by the idea of thread safety implemented by Rust, I want to make GPU command "thread" safety as well, I wrote code like this:
#![feature(negative_impls)]
#![feature(auto_traits)]
auto trait GpuSync {}
struct Buffer {}
impl Buffer {
pub fn render(&self) {}
}
impl ! GpuSync for Buffer {}
struct Queue {}
impl Queue {
pub fn submit<F>(&mut self, f: F) where F: FnOnce(), F: GpuSync {
f();
}
}
fn main() {
let mut queue = Queue {};
let buffer = Buffer {};
queue.submit(move || {
buffer.render();
});
}
it works perfect, the compiler will report an error saying that
within `[closure@src/main.rs:27:18: 29:6]`, the trait `GpuSync` is not implemented for `Buffer`
The only problem is that auto trait feature is not stable, I cannot use it in a stable version.
So is there any way I can manually implement GpuSync
on the closure type [closure@src/main.rs:27:18: 29:6]
?