Guest User

Untitled

a guest
Apr 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. trait SupportedFn<X> {
  2. fn arity(self) -> usize;
  3. }
  4.  
  5. // Support functions with 1 argument
  6. impl<T, R, F: Fn(T) -> R> SupportedFn<(T, R)> for F {
  7. fn arity(self) -> usize { 1 }
  8. }
  9.  
  10. // Support functions with 2 arguments
  11. impl<T, U, R, F: Fn(T, U) -> R> SupportedFn<(T, R, U)> for F {
  12. fn arity(self) -> usize { 2 }
  13. }
  14.  
  15. // Unfortunately, this does not work for real functions. :(
  16. fn f1(x: &u32) {}
  17. fn main() {
  18. println!("f1 takes {} args", f1.arity());
  19. }
Add Comment
Please, Sign In to add comment