Skip to content

Commit

Permalink
chore:switch to rust nightly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cedricschwyter committed Jul 1, 2023
1 parent e3bc19d commit 021c4a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 50 deletions.
66 changes: 16 additions & 50 deletions src-tauri/core/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),*) => {
Expand Down
1 change: 1 addition & 0 deletions src-tauri/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(macro_metavar_expr)]
pub mod core;

use clap::Parser;
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

0 comments on commit 021c4a7

Please sign in to comment.