check_ends_macro/
lib.rs

1/// Checks if string starts with any of the `&str`s
2#[macro_export]
3macro_rules! match_start {
4    ($to_check:expr, $( $( $start:literal)|* => $to_return:expr )* ) => {
5        if false {None} // This is here to use else if later
6        $(
7            else if match_start!(@INTERNAL $to_check, $($start),*) {
8                Some($to_return)
9            }
10        )*
11        else {None}
12    };
13
14    (@INTERNAL $to_check:expr, $($start:literal),*) => {
15        $(
16            $to_check.starts_with($start)
17        )||*
18    }
19}
20
21/// Checks if string ends with any of the `&str`s
22#[macro_export]
23macro_rules! match_end {
24    ($to_check:expr, $( $( $end:literal)|* => $to_return:expr )* ) => {
25        if false {None} // This is here to use else if later
26        $(
27            else if match_end!(@INTERNAL $to_check, $($end),*) {
28                Some($to_return)
29            }
30        )*
31        else {None}
32    };
33
34    (@INTERNAL $to_check:expr, $($start:literal),*) => {
35        $(
36            $to_check.ends_with($start)
37        )||*
38    }
39}