#[macro_export]
macro_rules! api_v1 {
( $( $i:ident, $l:literal ), *) => {
pub const API_V1: &str = "/api/v1";
pub mod path {
$(
pub const $i: &str = $l;
)*
}
pub mod full_path {
use const_format::concatcp;
$(
pub const $i: &str = concatcp!(super::API_V1, $l);
)*
}
};
}
#[cfg(test)]
mod api_v1_tests {
api_v1!(FOO, "/foo", BAR, "/bar");
#[test]
#[allow(non_snake_case)]
fn WHEN_paths_are_macroed_THEN_consts_in_both_modules() {
assert_eq!(path::FOO, "/foo");
assert_eq!(path::BAR, "/bar");
assert_eq!(full_path::FOO, "/api/v1/foo");
assert_eq!(full_path::BAR, "/api/v1/bar");
}
}