madsmtm / objc2

Bindings to Apple's frameworks in Rust
https://docs.rs/objc2/
MIT License
280 stars 35 forks source link

Avoid tuple in `Block::call` #575

Open madsmtm opened 3 months ago

madsmtm commented 3 months ago

Calling blocks should be possible without having to specify the awkward tuple argument (i.e. block.call((42,))).

Idea for solution (playground), credit to @yury for the idea:

impl<R> Block<dyn Fn() -> R> {
    pub fn call(&self) -> R { unimplemented!() }
}

impl<A, R> Block<dyn Fn(A) -> R> {
    pub fn call(&self, arg0: A) -> R { unimplemented!() }
}

// ...

Though of course, with the fn_traits feature, this would be even prettier.