Open
Description
openedon Oct 7, 2020
I could avoid some unsafe code if the types of functions and closures-without-captures implemented the Default trait.
Theoretically you could extend this to closures that only capture things implementing Default
, but starting with only closures that have no captures seems like a safer bet, and it can always be extended later.
Example:
fn call_by_type<F: Fn() + Copy + Default>() {
let f = F::default();
f();
}
fn wrapper<F: Fn() + Copy + Default>(_f: F) {
call_by_type::<F>();
}
fn foo() {
println!("Hello, world!");
}
fn main() {
wrapper(foo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels