Skip to content

Commit 505e835

Browse files
committed
feat: v10.14.9
1 parent 6c9a35c commit 505e835

3 files changed

Lines changed: 37 additions & 15 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hyperlane-macros"
3-
version = "10.14.8"
3+
version = "10.14.9"
44
readme = "README.md"
55
edition = "2024"
66
authors = ["root@ltpp.vip"]

debug/src/main.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ impl ServerHook for EpilogueHooks {
186186
async fn handle(self, ctx: &Context) {}
187187
}
188188

189-
async fn prologue_hooks_fn(ctx: Context) {
190-
let hook = PrologueHooks::new(&ctx).await;
191-
hook.handle(&ctx).await;
189+
async fn prologue_hooks_fn(ctx: &Context) {
190+
let hook = PrologueHooks::new(ctx).await;
191+
hook.handle(ctx).await;
192192
}
193193

194-
async fn epilogue_hooks_fn(ctx: Context) {
195-
let hook = EpilogueHooks::new(&ctx).await;
196-
hook.handle(&ctx).await;
194+
async fn epilogue_hooks_fn(ctx: &Context) {
195+
let hook = EpilogueHooks::new(ctx).await;
196+
hook.handle(ctx).await;
197197
}
198198

199199
#[route("/response")]
@@ -1654,6 +1654,28 @@ async fn standalone_prologue_hooks_handler(_ctx: &Context) {}
16541654
#[epilogue_hooks(epilogue_hooks_fn)]
16551655
async fn standalone_epilogue_hooks_handler(_ctx: &Context) {}
16561656

1657+
#[route("/hooks_expression")]
1658+
struct HooksExpression;
1659+
1660+
impl ServerHook for HooksExpression {
1661+
async fn new(_ctx: &Context) -> Self {
1662+
Self
1663+
}
1664+
1665+
#[get]
1666+
#[prologue_hooks(PrologueHooks::new_hook, PrologueHooks::method_hook)]
1667+
#[response_body("hooks expression test")]
1668+
async fn handle(self, ctx: &Context) {}
1669+
}
1670+
1671+
impl PrologueHooks {
1672+
async fn new_hook(_ctx: &Context) {
1673+
prologue_hooks_fn(_ctx).await;
1674+
}
1675+
1676+
async fn method_hook(_ctx: &Context) {}
1677+
}
1678+
16571679
#[hyperlane(server: Server)]
16581680
#[hyperlane(config: ServerConfig)]
16591681
#[tokio::main]

src/hook/fn.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ inventory::submit! {
7979
///
8080
/// # Arguments
8181
///
82-
/// - `TokenStream` - The attribute token stream containing a list of function names.
82+
/// - `TokenStream` - The attribute token stream containing a list of function names or expressions.
8383
/// - `TokenStream` - The input token stream to process.
8484
/// - `Position` - The position to inject the code.
8585
///
@@ -91,12 +91,12 @@ pub(crate) fn prologue_hooks_macro(
9191
item: TokenStream,
9292
position: Position,
9393
) -> TokenStream {
94-
let functions: Punctuated<Ident, Token![,]> =
94+
let functions: Punctuated<Expr, Token![,]> =
9595
parse_macro_input!(attr with Punctuated::parse_terminated);
9696
inject(position, item, |context| {
97-
let hook_calls = functions.iter().map(|function_name| {
97+
let hook_calls = functions.iter().map(|function_expr| {
9898
quote! {
99-
let _ = #function_name(#context.clone()).await;
99+
let _ = #function_expr(#context).await;
100100
}
101101
});
102102
quote! {
@@ -116,7 +116,7 @@ inventory::submit! {
116116
///
117117
/// # Arguments
118118
///
119-
/// - `TokenStream` - The attribute token stream containing a list of function names.
119+
/// - `TokenStream` - The attribute token stream containing a list of function names or expressions.
120120
/// - `TokenStream` - The input token stream to process.
121121
/// - `Position` - The position to inject the code.
122122
///
@@ -128,12 +128,12 @@ pub(crate) fn epilogue_hooks_macro(
128128
item: TokenStream,
129129
position: Position,
130130
) -> TokenStream {
131-
let functions: Punctuated<Ident, Token![,]> =
131+
let functions: Punctuated<Expr, Token![,]> =
132132
parse_macro_input!(attr with Punctuated::parse_terminated);
133133
inject(position, item, |context| {
134-
let hook_calls = functions.iter().map(|function_name| {
134+
let hook_calls = functions.iter().map(|function_expr| {
135135
quote! {
136-
let _ = #function_name(#context.clone()).await;
136+
let _ = #function_expr(#context).await;
137137
}
138138
});
139139
quote! {

0 commit comments

Comments
 (0)