Skip to content

Commit

Permalink
✨ 实现异步业务函数
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Dec 22, 2023
1 parent 1b6880f commit 4217678
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 33 deletions.
117 changes: 117 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ sha2 = "0.10.8"
scrypt = "0.11.0"
regex = "1.10.2"
serde_json = "1.0.108"
oblivion-codegen = { path = "oblivion-codegen" }
proc-macro2 = "1"
futures = "0.3"

[lib]
name = "oblivion"
1 change: 1 addition & 0 deletions oblivion-codegen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
182 changes: 182 additions & 0 deletions oblivion-codegen/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions oblivion-codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "oblivion-codegen"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures = "0.3.29"
quote = "1.0"
proc-macro2 = "1"
syn = { version = "2.0", features = ["full"] }

[lib]
bin = "oblivion_codegen"
proc-macro = true
25 changes: 25 additions & 0 deletions oblivion-codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemFn};

#[proc_macro_attribute]
pub fn async_route(_: TokenStream, item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as ItemFn);

let func_name = &input.sig.ident;
let func_args = &input.sig.inputs;
let func_block = input.block;

let expanded = quote! {


pub fn #func_name(#func_args) -> BoxFuture<'static, BaseResponse>
{
async move {
#func_block
}.boxed()
}
};

TokenStream::from(expanded)
}
Loading

0 comments on commit 4217678

Please sign in to comment.