aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/contrib/admin/site/urls.rs9
-rw-r--r--src/urls.rs59
2 files changed, 62 insertions, 6 deletions
diff --git a/src/contrib/admin/site/urls.rs b/src/contrib/admin/site/urls.rs
index ef23d55..d6537bc 100644
--- a/src/contrib/admin/site/urls.rs
+++ b/src/contrib/admin/site/urls.rs
@@ -1,7 +1,8 @@
-use crate::http::{Filter, Reply};
-use crate::urls::{UrlMap, path};
+use crate::http::Reply;
+use crate::urls::{UrlMap, url_map};
pub fn urls() -> UrlMap {
- path::end().map(|| Reply::into_response("bruh"))
- .boxed()
+ url_map! {
+ => || Reply::into_response("bruh"),
+ }
}
diff --git a/src/urls.rs b/src/urls.rs
index 45720b6..80eba9e 100644
--- a/src/urls.rs
+++ b/src/urls.rs
@@ -1,5 +1,60 @@
-pub use warp::path;
-
use crate::http::Response;
+pub use crate::url_map;
pub type UrlMap = warp::filters::BoxedFilter<(Response,)>;
+
+#[doc(hidden)]
+#[macro_export]
+macro_rules! __url_map_inner {
+ (@root => $view:expr, $($rest:tt)*) => {{
+ let chain = $crate::__url_map_inner!(@one => $view);
+ $crate::__url_map_inner!(chain @rest $($rest)*)
+ }};
+ (@root $head:tt $(/ $tail:tt)* => $view:expr, $($rest:tt)*) => {{
+ let chain = $crate::__url_map_inner!(@one $head $(/ $tail)* => $view);
+ $crate::__url_map_inner!(chain @rest $($rest)*)
+ }};
+ (@root $head:tt $(/ $tail:tt)* $child:expr, $($rest:tt)*) => {{
+ let chain = $crate::__url_map_inner!(@one $head $(/ $tail)* $child);
+ $crate::__url_map_inner!(chain @rest $($rest)*)
+ }};
+
+ ($chain:ident @rest => $view:expr, $($rest:tt)*) => {{
+ let chain = $chain
+ .or($crate::__url_map_inner!(@one => $view))
+ .unify();
+ $crate::__url_map_inner!(chain @rest $($rest)*)
+ }};
+ ($chain:ident @rest $head:tt $(/ $tail:tt)* => $view:expr, $($rest:tt)*) => {{
+ let chain = $chain
+ .or($crate::__url_map_inner!(@one $head $(/ $tail)* => $view))
+ .unify();
+ $crate::__url_map_inner!(chain @rest $($rest)*)
+ }};
+ ($chain:ident @rest $head:tt $(/ $tail:tt)* $child:expr, $($rest:tt)*) => {{
+ let chain = $chain
+ .or($crate::__url_map_inner!(@one $head $(/ $tail)* $child))
+ .unify();
+ $crate::__url_map_inner!(chain @rest $($rest)*)
+ }};
+ ($chain:ident @rest) => { $chain };
+
+ (@one => $view:expr) => {
+ ::warp::path::end().map($view)
+ };
+ (@one $head:tt $(/ $tail:tt)* => $view:expr) => {
+ ::warp::path!($head $(/ $tail)*).map($view)
+ };
+ (@one $head:tt $(/ $tail:tt)* $child:expr) => {
+ ::warp::path!($head $(/ $tail)*).and($child)
+ };
+}
+
+#[macro_export]
+macro_rules! url_map {
+ ($($body:tt)*) => {{
+ use ::warp::Filter;
+ $crate::__url_map_inner!(@root $($body)*)
+ .boxed()
+ }};
+}