Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait SupportedFn<X> {
- fn arity(self) -> usize;
- }
- // Support functions with 1 argument
- impl<T, R, F: Fn(T) -> R> SupportedFn<(T, R)> for F {
- fn arity(self) -> usize { 1 }
- }
- // Support functions with 2 arguments
- impl<T, U, R, F: Fn(T, U) -> R> SupportedFn<(T, R, U)> for F {
- fn arity(self) -> usize { 2 }
- }
- // Unfortunately, this does not work for real functions. :(
- fn f1(x: &u32) {}
- fn main() {
- println!("f1 takes {} args", f1.arity());
- }
Add Comment
Please, Sign In to add comment