-
Notifications
You must be signed in to change notification settings - Fork 52
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
[Assignment ?][11/13 Lecture Question] "Is it possible to define a generic closure in Rust?" #424
Comments
There isn't. I'm not sure why it isn't supported, but my guess is that closures are typically single-use functions, so there is no real point on making it generic in the most case. |
Thank you!! |
I came across an RFC about adding generic closures, but it seems like it's been postponed forever—just like so many other cool features proposed for Rust... rust-lang/rfcs#1650 (comment):
Nonetheless, the syntax you've tried for ( Closures are
|
Related Issue
https://github.com/nrc/r4cppp/blob/master/closures.md
Googling Result
https://users.rust-lang.org/t/use-generics-in-closure/86679
ChatGPT Result
https://chatgpt.com/c/
Your question here
I tried defining a generic closure in Rust like this:
However, this produces a compiler error: expected one of ':' , ';', '=', '@', or '|'. I understand that closures in Rust infer types based on their first use, but is there a way to explicitly make a closure generic without wrapping it in a function or struct? If not, could you explain why this limitation exists?
The text was updated successfully, but these errors were encountered: