Why can’t the type of capturing closures be named?
What is the reason for opaque types like closure@main.rs:10:65: 10:78 x:_, y:_]?
Couldn’t capturing closures be implemented with types like:
struct Capturing<E, F> {
environment: E,
fn_ptr: F,
}
let x = 1;
let y = 2;
let lambda: Capturing<(&isize, &isize), fn(&isize, &isize, &isize) -> &isize> = |n| x + y + n;
let mut foo = "foo";
let mut make_bar: Capturing<(&mut usize), fn(&mut str)> = || foo = "bar";
let foo = "foo".to_owned();
let foo_with: Capturing<(String), fn(String, String)> = move |suffix: String| println!("{}{}", foo, suffix);
// Relevant impls would be generated; E.g:
impl FnOnce(String) for Capturing<(String), fn(String, String)> {}
Currying could be implemented by generating implementations of Fn* traits for each case/arity of partial application.
Am I missing something that requires capturing closures be opaque?