Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: implicit generic function arguments with bounds #302
Comments
rust-highfive
referenced this issue
Sep 24, 2014
Closed
RFC: implicit generic function arguments with bounds #11196
This comment has been minimized.
This comment has been minimized.
|
I think this is |
scottmcm
closed this
Jan 19, 2018
This comment has been minimized.
This comment has been minimized.
|
@scottmcm Yeah, that's the explicit version of this. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rust-highfive commentedSep 24, 2014
Sunday Dec 29, 2013 at 19:35 GMT
For earlier discussion, see rust-lang/rust#11196
This issue was labelled with: B-RFC in the Rust repository
Using generic functions with trait bounds results in efficient code generation, at the cost of syntactic simplicity (compared to using trait objects).
Consider this snippet:
Now with trait bounds moved to argument types (creating implicit generic type parameters):
Note that this would be limited to values as references or pointers would conflict with current syntax for trait objects.
However, optimizing
&Traitin an argument type (or even a structure field? there is room for discussion here) to a generic (<T: Trait> ... &T) wouldn't cause any serious issues AFAICT.And it would mean we can make the closure syntax be sugar for
&Fnwithout losing backwards compatibility while allowing compile-time monomorphization.