Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- // This works
- thing_to_do(able_to_pass);
- // Does not work
- thing_to_do(fn() {
- println!("found fn in indent position");
- });
- // Not the same type
- thing_to_do(|| {
- println!("mismatched types: expected `fn()` but found `||`")
- });
- }
- fn thing_to_do(execute: fn()) {
- execute();
- }
- fn able_to_pass() {
- println!("Hey, I worked!");
- }
- fn main() {
- thing_to_do(able_to_pass);
- thing_to_do(|| {
- println!("works!");
- });
- }
- fn thing_to_do<F: FnOnce()>(func: F) {
- func();
- }
- fn able_to_pass() {
- println!("works!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement