1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ Copyright: (c) 2023, Mike 'PhiSyX' S. (https://github.com/PhiSyX) ┃
// ┃ SPDX-License-Identifier: MPL-2.0 ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ ┃
// ┃ This Source Code Form is subject to the terms of the Mozilla Public ┃
// ┃ License, v. 2.0. If a copy of the MPL was not distributed with this ┃
// ┃ file, You can obtain one at https://mozilla.org/MPL/2.0/. ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
#[macro_export]
macro_rules! routes {
(
pub enum $enum_route:ident<$l:lifetime> {
$(
#[route(url = $url:literal)]
$variant:ident
$({
$($field:ident : $type:ty),*
})?
),*,
}
) => {
pub enum $enum_route<$l> {
#[non_exhaustive] PhantomData(std::marker::PhantomData<&$l ()>),
$(
$variant $({
$($field : $type),*
})?,
)*
}
impl std::fmt::Display for $enum_route<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let route = match self {
Self::PhantomData(_) => unimplemented!(),
$(
| Self::$variant $({ $($field),* })? => format!($url),
)*
};
write!(f, "{route}")
}
}
impl std::fmt::Debug for $enum_route<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::PhantomData(_) => unimplemented!(),
$(
#[allow(dead_code)]
| Self::$variant $({ $($field),* })? => write!(f, stringify!($variant)),
)*
}
}
}
};
}