Created
April 7, 2016 02:41
-
-
Save Sgeo/6055c51710245c6b43154bf2d9771152 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trait Identity { | |
| fn call<T>(&self, T) -> T; | |
| } | |
| macro_rules! id { | |
| ($closure:expr) => {{ | |
| struct ThisID; | |
| impl Identity for ThisID { | |
| fn call<T>(&self, t: T) -> T { | |
| $closure(t) | |
| } | |
| } | |
| ThisID | |
| }} | |
| } | |
| fn wants_id<F: Identity>(f: F) { | |
| f.call(5); | |
| f.call("Hello"); | |
| } | |
| fn main() { | |
| wants_id(id!(|a| a)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment