#[macro_export]
macro_rules! matcher {
($m1:expr) => (
&|args| -> bool { match_impl_1(args, ($m1)) }
);
($m1:expr, $m2:expr) => (
&|args| -> bool { match_impl_2(args, ($m1, $m2)) }
);
($m1:expr, $m2:expr, $m3:expr) => (
&|args| -> bool { match_impl_3(args, ($m1, $m2, $m3)) }
);
($m1:expr, $m2:expr, $m3:expr, $m4:expr) => (
&|args| -> bool { match_impl_4(args, ($m1, $m2, $m3, $m4)) }
);
($m1:expr, $m2:expr, $m3:expr, $m4:expr, $m5:expr) => (
&|args| -> bool { match_impl_5(args, ($m1, $m2, $m3, $m4, $m5)) }
);
($m1:expr, $m2:expr, $m3:expr, $m4:expr, $m5:expr, $m6:expr) => (
&|args| -> bool { match_impl_6(args, ($m1, $m2, $m3, $m4, $m5, $m6)) }
);
($m1:expr, $m2:expr, $m3:expr, $m4:expr, $m5:expr, $m6:expr, $m7:expr) => (
&|args| -> bool { match_impl_7(args, ($m1, $m2, $m3, $m4, $m5, $m6, $m7)) }
);
($m1:expr, $m2:expr, $m3:expr, $m4:expr, $m5:expr, $m6:expr, $m7:expr, $m8:expr) => (
&|args| -> bool { match_impl_8(args, ($m1, $m2, $m3, $m4, $m5, $m6, $m7, $m8)) }
);
($m1:expr, $m2:expr, $m3:expr, $m4:expr, $m5:expr, $m6:expr, $m7:expr, $m8:expr, $m9:expr) => (
&|args| -> bool { match_impl_9(args, ($m1, $m2, $m3, $m4, $m5, $m6, $m7, $m8, $m9)) }
);
($m1:expr, $m2:expr, $m3:expr, $m4:expr, $m5:expr, $m6:expr, $m7:expr, $m8:expr, $m9:expr, $m10:expr) => (
&|args| -> bool { match_impl_10(args, ($m1, $m2, $m3, $m4, $m5, $m6, $m7, $m8, $m9, $m10)) }
);
($m1:expr, $m2:expr, $m3:expr, $m4:expr, $m5:expr, $m6:expr, $m7:expr, $m8:expr, $m9:expr, $m10:expr, $m11:expr) => (
&|args| -> bool { match_impl_11(args, ($m1, $m2, $m3, $m4, $m5, $m6, $m7, $m8, $m9, $m10, $m11)) }
);
}
pub fn match_impl_1<A>(arg: &A, arg_matcher: &Fn(&A) -> bool) -> bool {
arg_matcher(arg)
}
pub fn match_impl_2<A,B>(args: &(
A,
B
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1)
);
!matches.iter().any(|is_match| !is_match)
}
pub fn match_impl_3<A,B,C>(args: &(
A,
B,
C
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool,
&Fn(&C) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1),
arg_matchers.2(&args.2)
);
!matches.iter().any(|is_match| !is_match)
}
pub fn match_impl_4<A,B,C,D>(args: &(
A,
B,
C,
D
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool,
&Fn(&C) -> bool,
&Fn(&D) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1),
arg_matchers.2(&args.2),
arg_matchers.3(&args.3)
);
!matches.iter().any(|is_match| !is_match)
}
pub fn match_impl_5<A,B,C,D,E>(args: &(
A,
B,
C,
D,
E
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool,
&Fn(&C) -> bool,
&Fn(&D) -> bool,
&Fn(&E) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1),
arg_matchers.2(&args.2),
arg_matchers.3(&args.3),
arg_matchers.4(&args.4)
);
!matches.iter().any(|is_match| !is_match)
}
pub fn match_impl_6<A,B,C,D,E,F>(args: &(
A,
B,
C,
D,
E,
F
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool,
&Fn(&C) -> bool,
&Fn(&D) -> bool,
&Fn(&E) -> bool,
&Fn(&F) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1),
arg_matchers.2(&args.2),
arg_matchers.3(&args.3),
arg_matchers.4(&args.4),
arg_matchers.5(&args.5)
);
!matches.iter().any(|is_match| !is_match)
}
pub fn match_impl_7<A,B,C,D,E,F,G>(args: &(
A,
B,
C,
D,
E,
F,
G
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool,
&Fn(&C) -> bool,
&Fn(&D) -> bool,
&Fn(&E) -> bool,
&Fn(&F) -> bool,
&Fn(&G) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1),
arg_matchers.2(&args.2),
arg_matchers.3(&args.3),
arg_matchers.4(&args.4),
arg_matchers.5(&args.5),
arg_matchers.6(&args.6)
);
!matches.iter().any(|is_match| !is_match)
}
pub fn match_impl_8<A,B,C,D,E,F,G,H>(args: &(
A,
B,
C,
D,
E,
F,
G,
H
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool,
&Fn(&C) -> bool,
&Fn(&D) -> bool,
&Fn(&E) -> bool,
&Fn(&F) -> bool,
&Fn(&G) -> bool,
&Fn(&H) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1),
arg_matchers.2(&args.2),
arg_matchers.3(&args.3),
arg_matchers.4(&args.4),
arg_matchers.5(&args.5),
arg_matchers.6(&args.6),
arg_matchers.7(&args.7)
);
!matches.iter().any(|is_match| !is_match)
}
pub fn match_impl_9<A,B,C,D,E,F,G,H,I>(args: &(
A,
B,
C,
D,
E,
F,
G,
H,
I
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool,
&Fn(&C) -> bool,
&Fn(&D) -> bool,
&Fn(&E) -> bool,
&Fn(&F) -> bool,
&Fn(&G) -> bool,
&Fn(&H) -> bool,
&Fn(&I) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1),
arg_matchers.2(&args.2),
arg_matchers.3(&args.3),
arg_matchers.4(&args.4),
arg_matchers.5(&args.5),
arg_matchers.6(&args.6),
arg_matchers.7(&args.7),
arg_matchers.8(&args.8)
);
!matches.iter().any(|is_match| !is_match)
}
pub fn match_impl_10<A,B,C,D,E,F,G,H,I,J>(args: &(
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool,
&Fn(&C) -> bool,
&Fn(&D) -> bool,
&Fn(&E) -> bool,
&Fn(&F) -> bool,
&Fn(&G) -> bool,
&Fn(&H) -> bool,
&Fn(&I) -> bool,
&Fn(&J) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1),
arg_matchers.2(&args.2),
arg_matchers.3(&args.3),
arg_matchers.4(&args.4),
arg_matchers.5(&args.5),
arg_matchers.6(&args.6),
arg_matchers.7(&args.7),
arg_matchers.8(&args.8),
arg_matchers.9(&args.9)
);
!matches.iter().any(|is_match| !is_match)
}
pub fn match_impl_11<A,B,C,D,E,F,G,H,I,J,K>(args: &(
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
),
arg_matchers: (
&Fn(&A) -> bool,
&Fn(&B) -> bool,
&Fn(&C) -> bool,
&Fn(&D) -> bool,
&Fn(&E) -> bool,
&Fn(&F) -> bool,
&Fn(&G) -> bool,
&Fn(&H) -> bool,
&Fn(&I) -> bool,
&Fn(&J) -> bool,
&Fn(&K) -> bool
)) -> bool {
let matches = vec!(
arg_matchers.0(&args.0),
arg_matchers.1(&args.1),
arg_matchers.2(&args.2),
arg_matchers.3(&args.3),
arg_matchers.4(&args.4),
arg_matchers.5(&args.5),
arg_matchers.6(&args.6),
arg_matchers.7(&args.7),
arg_matchers.8(&args.8),
arg_matchers.9(&args.9),
arg_matchers.10(&args.10)
);
!matches.iter().any(|is_match| !is_match)
}
#[macro_export]
macro_rules! p {
($func:ident) => (
&|potential_match| -> bool {{ $func(potential_match) }}
);
($func:ident, $arg1:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1) }
);
($func:ident, $arg1:expr, $arg2:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2) }
);
($func:ident, $arg1:expr, $arg2:expr, $arg3:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2, $arg3) }
);
($func:ident, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2, $arg3, $arg4) }
);
($func:ident, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2, $arg3, $arg4, $arg5) }
);
($func:ident, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr, $arg6:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6) }
);
($func:ident, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr, $arg6:expr, $arg7:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7) }
);
($func:ident, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr, $arg6:expr, $arg7:expr, $arg8:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8) }
);
($func:ident, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr, $arg6:expr, $arg7:expr, $arg8:expr, $arg9:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8, $arg9) }
);
($func:ident, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr, $arg6:expr, $arg7:expr, $arg8:expr, $arg9:expr, $arg10:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8, $arg9, $arg10) }
);
($func:ident, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr, $arg6:expr, $arg7:expr, $arg8:expr, $arg9:expr, $arg10:expr, $arg11:expr) => (
&|potential_match| -> bool { $func(potential_match, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8, $arg9, $arg10, $arg11) }
);
}