Skip to content

hof: No explanation how to create a function that takes a closure #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kornelski opened this issue Jan 13, 2015 · 3 comments
Closed

hof: No explanation how to create a function that takes a closure #406

kornelski opened this issue Jan 13, 2015 · 3 comments

Comments

@kornelski
Copy link
Contributor

The example uses preexisting functions accepting closures, but doesn't show how to create one.

I'm struggling with this, because the compiler won't infer the closure type, and closure types were not explained (related #405).

fn callme<T>(callable: T) {
    callable(12i32);
}

fn main() {
    callme(|&:arg| -arg);
}

error: expected function, found T

@strega-nil
Copy link

fn callme<F>(callable: F)
        where F: Fn(i32) -> i32 {
    println!("{}", callable(12i32));
}

@mdinger
Copy link
Contributor

mdinger commented Jun 15, 2015

The closures section now includes an example covering this case. This should be fixed.

@kornelski
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants