From df0f69b4c713a8a770c6abe265dbf3987833bf21 Mon Sep 17 00:00:00 2001 From: Cedric Schwyter Date: Sat, 1 Jul 2023 16:54:15 +0200 Subject: [PATCH] chore:switch to rust nightly refactor:higher-order http method macro we want to switch to rust nightly to be able to make use of rust metavariable expansions as defined by RFC rust-lang/rfcs#3086 and as tracked by rust-lang/rust#83527. other references include rust-lang/rust#99035. this feature was stabilized in 1.63, then unstabilized again in rust-lang/rust#99435 and is now only available in rust nightly, awaiting restabilization. however, the feature is stable enough for our use case, which is why i'm going ahead and enabling it. --- src-tauri/core/macros.rs | 66 +++++++++-------------------------- src-tauri/lib.rs | 1 + src-tauri/rust-toolchain.toml | 2 ++ 3 files changed, 19 insertions(+), 50 deletions(-) create mode 100644 src-tauri/rust-toolchain.toml diff --git a/src-tauri/core/macros.rs b/src-tauri/core/macros.rs index 64fbb44..6afa058 100644 --- a/src-tauri/core/macros.rs +++ b/src-tauri/core/macros.rs @@ -29,59 +29,25 @@ macro_rules! endpoint { }; } -macro_rules! get { - ($endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { - endpoint!(get, $endpoint, $endpointname, $returntype $(, $body)? $(, [$($param),+])?); - }; -} - -macro_rules! head { - ($endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { - endpoint!(head, $endpoint, $endpointname, $returntype $(, $body)? $(, [$($param),+])?); - }; -} - -macro_rules! post { - ($endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { - endpoint!(post, $endpoint, $endpointname, $returntype $(, $body)? $(, [$($param),+])?); - }; -} - -macro_rules! put { - ($endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { - endpoint!(put, $endpoint, $endpointname, $returntype $(, $body)? $(, [$($param),+])?); - }; -} - -macro_rules! delete { - ($endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { - endpoint!(delete, $endpoint, $endpointname, $returntype $(, $body)? $(, [$($param),+])?); - }; -} - -macro_rules! connect { - ($endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { - endpoint!(connect, $endpoint, $endpointname, $returntype $(, $body)? $(, [$($param),+])?); - }; -} - -macro_rules! options { - ($endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { - endpoint!(options, $endpoint, $endpointname, $returntype $(, $body)? $(, [$($param),+])?); - }; -} - -macro_rules! trace { - ($endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { - endpoint!(trace, $endpoint, $endpointname, $returntype $(, $body)? $(, [$($param),+])?); +macro_rules! http_method { + ($method:ident) => { + macro_rules! $method { + ($$endpoint:expr, $$endpointname:ident, $$returntype:ident $$(, $$body:ident)? $$(, [$$($$param:expr),+])?) => { + endpoint!($method, $$endpoint, $$endpointname, $returntype $$(, $$body)? $$(, [$$($$param),+])?); + }; + } }; } -macro_rules! patch { - ($endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { - endpoint!(patch, $endpoint, $endpointname, $returntype $(, $body)? $(, [$($param),+])?); - }; -} +http_method!(get); +http_method!(head); +http_method!(post); +http_method!(put); +http_method!(delete); +http_method!(connect); +http_method!(options); +http_method!(trace); +http_method!(patch); macro_rules! handlers { ($($handler:ident),*) => { diff --git a/src-tauri/lib.rs b/src-tauri/lib.rs index 81ea237..a2ff9da 100644 --- a/src-tauri/lib.rs +++ b/src-tauri/lib.rs @@ -1,3 +1,4 @@ +#![feature(macro_metavar_expr)] pub mod core; use clap::Parser; diff --git a/src-tauri/rust-toolchain.toml b/src-tauri/rust-toolchain.toml new file mode 100644 index 0000000..5d56faf --- /dev/null +++ b/src-tauri/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly"