hyperlane_macros/lib.rs
1//! hyperlane-macros
2//!
3//! A comprehensive collection of procedural macros for building
4//! HTTP servers with enhanced functionality. This crate provides
5//! attribute macros that simplify HTTP request handling, protocol
6//! validation, response management, and request data extraction.
7
8mod aborted;
9mod closed;
10mod common;
11mod filter;
12mod flush;
13mod hook;
14mod host;
15mod http;
16mod hyperlane;
17mod protocol;
18mod referer;
19mod request;
20mod response;
21mod send;
22
23pub(crate) use aborted::*;
24pub(crate) use closed::*;
25pub(crate) use common::*;
26pub(crate) use filter::*;
27pub(crate) use flush::*;
28pub(crate) use hook::*;
29pub(crate) use host::*;
30pub(crate) use http::*;
31pub(crate) use hyperlane::*;
32pub(crate) use protocol::*;
33pub(crate) use referer::*;
34pub(crate) use request::*;
35pub(crate) use response::*;
36pub(crate) use send::*;
37
38pub(crate) use proc_macro::TokenStream;
39pub(crate) use proc_macro2::TokenStream as TokenStream2;
40pub(crate) use quote::quote;
41pub(crate) use syn::{
42 Ident, Token,
43 parse::{Parse, ParseStream, Result},
44 punctuated::Punctuated,
45 *,
46};
47
48/// Restricts function execution to HTTP GET requests only.
49///
50/// This attribute macro ensures the decorated function only executes when the incoming request
51/// uses the GET HTTP method. Requests with other methods will be filtered out.
52///
53/// # Usage
54///
55/// ```rust
56/// use hyperlane::*;
57/// use hyperlane_macros::*;
58///
59/// #[get]
60/// async fn handle_get(ctx: Context) {
61/// // Function body
62/// }
63/// ```
64///
65/// The macro takes no parameters and should be applied directly to async functions
66/// that accept a `Context` parameter.
67#[proc_macro_attribute]
68pub fn get(_attr: TokenStream, item: TokenStream) -> TokenStream {
69 get_handler(item)
70}
71
72/// Restricts function execution to HTTP POST requests only.
73///
74/// This attribute macro ensures the decorated function only executes when the incoming request
75/// uses the POST HTTP method. Requests with other methods will be filtered out.
76///
77/// # Usage
78///
79/// ```rust
80/// use hyperlane::*;
81/// use hyperlane_macros::*;
82///
83/// #[post]
84/// async fn handle_post(ctx: Context) {
85/// // Function body
86/// }
87/// ```
88///
89/// The macro takes no parameters and should be applied directly to async functions
90/// that accept a `Context` parameter.
91#[proc_macro_attribute]
92pub fn post(_attr: TokenStream, item: TokenStream) -> TokenStream {
93 post_handler(item)
94}
95
96/// Restricts function execution to HTTP PUT requests only.
97///
98/// This attribute macro ensures the decorated function only executes when the incoming request
99/// uses the PUT HTTP method. Requests with other methods will be filtered out.
100///
101/// # Usage
102///
103/// ```rust
104/// use hyperlane::*;
105/// use hyperlane_macros::*;
106///
107/// #[put]
108/// async fn handle_put(ctx: Context) {
109/// // Function body
110/// }
111/// ```
112///
113/// The macro takes no parameters and should be applied directly to async functions
114/// that accept a `Context` parameter.
115#[proc_macro_attribute]
116pub fn put(_attr: TokenStream, item: TokenStream) -> TokenStream {
117 put_handler(item)
118}
119
120/// Restricts function execution to HTTP DELETE requests only.
121///
122/// This attribute macro ensures the decorated function only executes when the incoming request
123/// uses the DELETE HTTP method. Requests with other methods will be filtered out.
124///
125/// # Usage
126///
127/// ```rust
128/// use hyperlane::*;
129/// use hyperlane_macros::*;
130///
131/// #[delete]
132/// async fn handle_delete(ctx: Context) {
133/// // Function body
134/// }
135/// ```
136///
137/// The macro takes no parameters and should be applied directly to async functions
138/// that accept a `Context` parameter.
139#[proc_macro_attribute]
140pub fn delete(_attr: TokenStream, item: TokenStream) -> TokenStream {
141 delete_handler(item)
142}
143
144/// Restricts function execution to HTTP PATCH requests only.
145///
146/// This attribute macro ensures the decorated function only executes when the incoming request
147/// uses the PATCH HTTP method. Requests with other methods will be filtered out.
148///
149/// # Usage
150///
151/// ```rust
152/// use hyperlane::*;
153/// use hyperlane_macros::*;
154///
155/// #[patch]
156/// async fn handle_patch(ctx: Context) {
157/// // Function body
158/// }
159/// ```
160///
161/// The macro takes no parameters and should be applied directly to async functions
162/// that accept a `Context` parameter.
163#[proc_macro_attribute]
164pub fn patch(_attr: TokenStream, item: TokenStream) -> TokenStream {
165 patch_handler(item)
166}
167
168/// Restricts function execution to HTTP HEAD requests only.
169///
170/// This attribute macro ensures the decorated function only executes when the incoming request
171/// uses the HEAD HTTP method. Requests with other methods will be filtered out.
172///
173/// # Usage
174///
175/// ```rust
176/// use hyperlane::*;
177/// use hyperlane_macros::*;
178///
179/// #[head]
180/// async fn handle_head(ctx: Context) {
181/// // Function body
182/// }
183/// ```
184///
185/// The macro takes no parameters and should be applied directly to async functions
186/// that accept a `Context` parameter.
187#[proc_macro_attribute]
188pub fn head(_attr: TokenStream, item: TokenStream) -> TokenStream {
189 head_handler(item)
190}
191
192/// Restricts function execution to HTTP OPTIONS requests only.
193///
194/// This attribute macro ensures the decorated function only executes when the incoming request
195/// uses the OPTIONS HTTP method. Requests with other methods will be filtered out.
196///
197/// # Usage
198///
199/// ```rust
200/// use hyperlane::*;
201/// use hyperlane_macros::*;
202///
203/// #[options]
204/// async fn handle_options(ctx: Context) {
205/// // Function body
206/// }
207/// ```
208///
209/// The macro takes no parameters and should be applied directly to async functions
210/// that accept a `Context` parameter.
211#[proc_macro_attribute]
212pub fn options(_attr: TokenStream, item: TokenStream) -> TokenStream {
213 options_handler(item)
214}
215
216/// Restricts function execution to HTTP CONNECT requests only.
217///
218/// This attribute macro ensures the decorated function only executes when the incoming request
219/// uses the CONNECT HTTP method. Requests with other methods will be filtered out.
220///
221/// # Usage
222///
223/// ```rust
224/// use hyperlane::*;
225/// use hyperlane_macros::*;
226///
227/// #[connect]
228/// async fn handle_connect(ctx: Context) {
229/// // Function body
230/// }
231/// ```
232///
233/// The macro takes no parameters and should be applied directly to async functions
234/// that accept a `Context` parameter.
235#[proc_macro_attribute]
236pub fn connect(_attr: TokenStream, item: TokenStream) -> TokenStream {
237 connect_handler(item)
238}
239
240/// Restricts function execution to HTTP TRACE requests only.
241///
242/// This attribute macro ensures the decorated function only executes when the incoming request
243/// uses the TRACE HTTP method. Requests with other methods will be filtered out.
244///
245/// # Usage
246///
247/// ```rust
248/// use hyperlane::*;
249/// use hyperlane_macros::*;
250///
251/// #[trace]
252/// async fn handle_trace(ctx: Context) {
253/// // Function body
254/// }
255/// ```
256///
257/// The macro takes no parameters and should be applied directly to async functions
258/// that accept a `Context` parameter.
259#[proc_macro_attribute]
260pub fn trace(_attr: TokenStream, item: TokenStream) -> TokenStream {
261 trace_handler(item)
262}
263
264/// Allows function to handle multiple HTTP methods.
265///
266/// This attribute macro configures the decorated function to execute for any of the specified
267/// HTTP methods. Methods should be provided as a comma-separated list.
268///
269/// # Usage
270///
271/// ```rust
272/// use hyperlane::*;
273/// use hyperlane_macros::*;
274///
275/// #[methods(get, post)]
276/// async fn handle_get_post(ctx: Context) {
277/// // Function body
278/// }
279///
280/// #[methods(put, patch, delete)]
281/// async fn handle_modifications(ctx: Context) {
282/// // Function body
283/// }
284/// ```
285///
286/// The macro accepts a comma-separated list of HTTP method names (lowercase) and should be
287/// applied to async functions that accept a `Context` parameter.
288#[proc_macro_attribute]
289pub fn methods(attr: TokenStream, item: TokenStream) -> TokenStream {
290 methods_macro(attr, item)
291}
292
293/// Restricts function execution to WebSocket upgrade requests only.
294///
295/// This attribute macro ensures the decorated function only executes when the incoming request
296/// is a valid WebSocket upgrade request with proper request headers and protocol negotiation.
297///
298/// # Usage
299///
300/// ```rust
301/// use hyperlane::*;
302/// use hyperlane_macros::*;
303///
304/// #[ws]
305/// async fn handle_websocket(ctx: Context) {
306/// // WebSocket handling logic
307/// }
308/// ```
309///
310/// The macro takes no parameters and should be applied directly to async functions
311/// that accept a `Context` parameter.
312#[proc_macro_attribute]
313pub fn ws(_attr: TokenStream, item: TokenStream) -> TokenStream {
314 ws_macro(item)
315}
316
317/// Restricts function execution to standard HTTP requests only.
318///
319/// This attribute macro ensures the decorated function only executes for standard HTTP requests,
320/// excluding WebSocket upgrades and other protocol upgrade requests.
321///
322/// # Usage
323///
324/// ```rust
325/// use hyperlane::*;
326/// use hyperlane_macros::*;
327///
328/// #[http]
329/// async fn handle_http(ctx: Context) {
330/// // HTTP request handling logic
331/// }
332/// ```
333///
334/// The macro takes no parameters and should be applied directly to async functions
335/// that accept a `Context` parameter.
336#[proc_macro_attribute]
337pub fn http(_attr: TokenStream, item: TokenStream) -> TokenStream {
338 http_macro(item)
339}
340
341/// Sets the HTTP status code for the response.
342///
343/// This attribute macro configures the HTTP status code that will be sent with the response.
344/// The status code can be provided as a numeric literal or a global constant.
345///
346/// # Usage
347///
348/// ```rust
349/// use hyperlane::*;
350/// use hyperlane_macros::*;
351///
352/// const CUSTOM_STATUS: i32 = 418;
353///
354/// #[response_status_code(200)]
355/// async fn success_handler(ctx: Context) {
356/// // Response will have status code 200
357/// }
358///
359/// #[response_status_code(404)]
360/// async fn not_found_handler(ctx: Context) {
361/// // Response will have status code 404
362/// }
363///
364/// #[response_status_code(CUSTOM_STATUS)]
365/// async fn custom_handler(ctx: Context) {
366/// // Response will have status code from global constant
367/// }
368/// ```
369///
370/// The macro accepts a numeric HTTP status code or a global constant
371/// and should be applied to async functions that accept a `Context` parameter.
372#[proc_macro_attribute]
373pub fn response_status_code(attr: TokenStream, item: TokenStream) -> TokenStream {
374 response_status_code_macro(attr, item)
375}
376
377/// Sets the HTTP reason phrase for the response.
378///
379/// This attribute macro configures the HTTP reason phrase that accompanies the status code.
380/// The reason phrase can be provided as a string literal or a global constant.
381///
382/// # Usage
383///
384/// ```rust
385/// use hyperlane::*;
386/// use hyperlane_macros::*;
387///
388/// const CUSTOM_REASON: &str = "I'm a teapot";
389///
390/// #[response_reason_phrase("OK")]
391/// async fn success_handler(ctx: Context) {
392/// // Response will have reason phrase "OK"
393/// }
394///
395/// #[response_reason_phrase("Not Found")]
396/// async fn not_found_handler(ctx: Context) {
397/// // Response will have reason phrase "Not Found"
398/// }
399///
400/// #[response_reason_phrase(CUSTOM_REASON)]
401/// async fn custom_handler(ctx: Context) {
402/// // Response will have reason phrase from global constant
403/// }
404/// ```
405///
406/// The macro accepts a string literal or global constant for the reason phrase and should be
407/// applied to async functions that accept a `Context` parameter.
408#[proc_macro_attribute]
409pub fn response_reason_phrase(attr: TokenStream, item: TokenStream) -> TokenStream {
410 response_reason_phrase_macro(attr, item)
411}
412
413/// Sets or replaces a specific HTTP response header.
414///
415/// This attribute macro configures a specific HTTP response header that will be sent with the response.
416/// Both the header name and value can be provided as string literals or global constants.
417/// Use `"key", "value"` to set a header (add to existing headers) or `"key" => "value"` to replace a header (overwrite existing).
418///
419/// # Usage
420///
421/// ```rust
422/// use hyperlane::*;
423/// use hyperlane_macros::*;
424///
425/// const HEADER_NAME: &str = "X-Custom-Header";
426/// const HEADER_VALUE: &str = "custom-value";
427///
428/// #[response_header("Content-Type", "application/json")]
429/// async fn json_handler(ctx: Context) {
430/// // Response will have Content-Type header set to application/json
431/// }
432///
433/// #[response_header("X-Static-Header" => "static-value")]
434/// async fn set_header_handler(ctx: Context) {
435/// // Response will have static header replaced (overwrite existing)
436/// }
437///
438/// #[response_header(HEADER_NAME, HEADER_VALUE)]
439/// async fn dynamic_header_handler(ctx: Context) {
440/// // Response will have header from global constants
441/// }
442///
443/// #[response_header("Cache-Control" => "no-cache")]
444/// async fn set_cache_handler(ctx: Context) {
445/// // Response will have Cache-Control header replaced
446/// }
447///
448/// #[response_header("X-Add-Header", "add-value")]
449/// #[response_header("X-Set-Header" => "set-value")]
450/// async fn header_operations_handler(ctx: Context) {
451/// // Response will have X-Add-Header set and X-Set-Header replaced
452/// }
453/// ```
454///
455/// The macro accepts header name and header value, both can be string literals or global constants.
456/// Use `"key", "value"` for setting headers and `"key" => "value"` for replacing headers.
457/// Should be applied to async functions that accept a `Context` parameter.
458#[proc_macro_attribute]
459pub fn response_header(attr: TokenStream, item: TokenStream) -> TokenStream {
460 response_header_macro(attr, item)
461}
462
463/// Sets the HTTP response body.
464///
465/// This attribute macro configures the HTTP response body that will be sent with the response.
466/// The body content can be provided as a string literal or a global constant.
467///
468/// # Usage
469///
470/// ```rust
471/// use hyperlane::*;
472/// use hyperlane_macros::*;
473///
474/// const RESPONSE_DATA: &str = "Dynamic content from constant";
475///
476/// #[response_body("Hello, World!")]
477/// async fn hello_handler(ctx: Context) {
478/// // Response will have body "Hello, World!"
479/// }
480///
481/// #[response_body("{\"message\": \"success\"}")]
482/// async fn json_response_handler(ctx: Context) {
483/// // Response will have JSON body
484/// }
485///
486/// #[response_body(RESPONSE_DATA)]
487/// async fn dynamic_body_handler(ctx: Context) {
488/// // Response will have body from global constant
489/// }
490/// ```
491///
492/// The macro accepts a string literal or global constant for the response body and should be
493/// applied to async functions that accept a `Context` parameter.
494#[proc_macro_attribute]
495pub fn response_body(attr: TokenStream, item: TokenStream) -> TokenStream {
496 response_body_macro(attr, item)
497}
498
499/// Sets the HTTP response version.
500///
501/// This attribute macro configures the HTTP response version that will be sent with the response.
502/// The version can be provided as a variable or code block.
503///
504/// # Usage
505///
506/// ```rust
507/// use hyperlane::*;
508/// use hyperlane_macros::*;
509///
510/// #[response_version(HttpVersion::HTTP1_1)]
511/// async fn version_from_constant(ctx: Context) {
512/// // Response will have version from global constant
513/// }
514/// ```
515///
516/// The macro accepts a variable or code block for the response version and should be
517/// applied to async functions that accept a `Context` parameter.
518#[proc_macro_attribute]
519pub fn response_version(attr: TokenStream, item: TokenStream) -> TokenStream {
520 response_version_macro(attr, item)
521}
522
523/// Automatically sends the complete response after function execution.
524///
525/// This attribute macro ensures that the response (request headers and body) is automatically sent
526/// to the client after the function completes execution.
527///
528/// # Usage
529///
530/// ```rust
531/// use hyperlane::*;
532/// use hyperlane_macros::*;
533///
534/// #[send]
535/// async fn auto_send_handler(ctx: Context) {
536/// let _ = ctx.set_response_body("Hello World").await;
537/// // Response is automatically sent after function returns
538/// }
539/// ```
540///
541/// The macro takes no parameters and should be applied directly to async functions
542/// that accept a `Context` parameter.
543#[proc_macro_attribute]
544pub fn send(_attr: TokenStream, item: TokenStream) -> TokenStream {
545 send_macro(item)
546}
547
548/// Automatically sends only the response body after function execution.
549///
550/// This attribute macro ensures that only the response body is automatically sent
551/// to the client after the function completes, handling request headers separately.
552///
553/// # Usage
554///
555/// ```rust
556/// use hyperlane::*;
557/// use hyperlane_macros::*;
558///
559/// #[send_body]
560/// async fn auto_send_body_handler(ctx: Context) {
561/// let _ = ctx.set_response_body("Response body content").await;
562/// // Only response body is automatically sent after function returns
563/// }
564/// ```
565///
566/// The macro takes no parameters and should be applied directly to async functions
567/// that accept a `Context` parameter.
568#[proc_macro_attribute]
569pub fn send_body(_attr: TokenStream, item: TokenStream) -> TokenStream {
570 send_body_macro(item)
571}
572
573/// Sends the complete response exactly once after function execution.
574///
575/// This attribute macro ensures that the response is sent exactly once to the client,
576/// preventing multiple response transmissions for single-use scenarios.
577///
578/// # Usage
579///
580/// ```rust
581/// use hyperlane::*;
582/// use hyperlane_macros::*;
583///
584/// #[send_once]
585/// async fn send_once_handler(ctx: Context) {
586/// let _ = ctx.set_response_body("One-time response").await;
587/// // Response is sent exactly once after function returns
588/// }
589/// ```
590///
591/// The macro takes no parameters and should be applied directly to async functions
592/// that accept a `Context` parameter.
593#[proc_macro_attribute]
594pub fn send_once(_attr: TokenStream, item: TokenStream) -> TokenStream {
595 send_once_macro(item)
596}
597
598/// Sends only the response body exactly once after function execution.
599///
600/// This attribute macro ensures that the response body is sent exactly once to the client,
601/// preventing multiple body transmissions for single-use scenarios.
602///
603/// # Usage
604///
605/// ```rust
606/// use hyperlane::*;
607/// use hyperlane_macros::*;
608///
609/// #[send_once_body]
610/// async fn send_once_body_handler(ctx: Context) {
611/// let _ = ctx.set_response_body("One-time body content").await;
612/// // Response body is sent exactly once after function returns
613/// }
614/// ```
615///
616/// The macro takes no parameters and should be applied directly to async functions
617/// that accept a `Context` parameter.
618#[proc_macro_attribute]
619pub fn send_once_body(_attr: TokenStream, item: TokenStream) -> TokenStream {
620 send_once_body_macro(item)
621}
622
623/// Flushes the response stream after function execution.
624///
625/// This attribute macro ensures that the response stream is flushed to guarantee immediate
626/// data transmission, forcing any buffered response data to be sent to the client.
627///
628/// # Usage
629///
630/// ```rust
631/// use hyperlane::*;
632/// use hyperlane_macros::*;
633///
634/// #[flush]
635/// async fn flush_handler(ctx: Context) {
636/// let _ = ctx.set_response_body("Immediate response").await;
637/// // Response stream is flushed after function returns
638/// }
639/// ```
640///
641/// The macro takes no parameters and should be applied directly to async functions
642/// that accept a `Context` parameter.
643#[proc_macro_attribute]
644pub fn flush(_attr: TokenStream, item: TokenStream) -> TokenStream {
645 flush_macro(item)
646}
647
648/// Handles aborted request scenarios.
649///
650/// This attribute macro configures the function to handle cases where the client has
651/// aborted the request, providing appropriate handling for interrupted or cancelled requests.
652///
653/// # Usage
654///
655/// ```rust
656/// use hyperlane::*;
657/// use hyperlane_macros::*;
658///
659/// #[aborted]
660/// async fn handle_aborted(ctx: Context) {
661/// // Handle aborted request logic
662/// }
663/// ```
664///
665/// The macro takes no parameters and should be applied directly to async functions
666/// that accept a `Context` parameter.
667#[proc_macro_attribute]
668pub fn aborted(_attr: TokenStream, item: TokenStream) -> TokenStream {
669 aborted_macro(item)
670}
671
672/// Handles closed connection scenarios.
673///
674/// This attribute macro configures the function to handle cases where the connection
675/// has been closed, providing appropriate handling for terminated or disconnected connections.
676///
677/// # Usage
678///
679/// ```rust
680/// use hyperlane::*;
681/// use hyperlane_macros::*;
682///
683/// #[closed]
684/// async fn handle_closed(ctx: Context) {
685/// // Handle closed connection logic
686/// }
687/// ```
688///
689/// The macro takes no parameters and should be applied directly to async functions
690/// that accept a `Context` parameter.
691#[proc_macro_attribute]
692pub fn closed(_attr: TokenStream, item: TokenStream) -> TokenStream {
693 closed_macro(item)
694}
695
696/// Restricts function execution to HTTP/2 Cleartext (h2c) requests only.
697///
698/// This attribute macro ensures the decorated function only executes for HTTP/2 cleartext
699/// requests that use the h2c upgrade mechanism.
700///
701/// # Usage
702///
703/// ```rust
704/// use hyperlane::*;
705/// use hyperlane_macros::*;
706///
707/// #[h2c]
708/// async fn handle_h2c(ctx: Context) {
709/// // Handle HTTP/2 cleartext requests
710/// }
711/// ```
712///
713/// The macro takes no parameters and should be applied directly to async functions
714/// that accept a `Context` parameter.
715#[proc_macro_attribute]
716pub fn h2c(_attr: TokenStream, item: TokenStream) -> TokenStream {
717 h2c_macro(item)
718}
719
720/// Restricts function execution to HTTP/0.9 requests only.
721///
722/// This attribute macro ensures the decorated function only executes for HTTP/0.9
723/// protocol requests, the earliest version of the HTTP protocol.
724///
725/// # Usage
726///
727/// ```rust
728/// use hyperlane::*;
729/// use hyperlane_macros::*;
730///
731/// #[http0_9]
732/// async fn handle_http09(ctx: Context) {
733/// // Handle HTTP/0.9 requests
734/// }
735/// ```
736///
737/// The macro takes no parameters and should be applied directly to async functions
738/// that accept a `Context` parameter.
739#[proc_macro_attribute]
740pub fn http0_9(_attr: TokenStream, item: TokenStream) -> TokenStream {
741 http0_9_macro(item)
742}
743
744/// Restricts function execution to HTTP/1.0 requests only.
745///
746/// This attribute macro ensures the decorated function only executes for HTTP/1.0
747/// protocol requests.
748///
749/// # Usage
750///
751/// ```rust
752/// use hyperlane::*;
753/// use hyperlane_macros::*;
754///
755/// #[http1_0]
756/// async fn handle_http10(ctx: Context) {
757/// // Handle HTTP/1.0 requests
758/// }
759/// ```
760///
761/// The macro takes no parameters and should be applied directly to async functions
762/// that accept a `Context` parameter.
763#[proc_macro_attribute]
764pub fn http1_0(_attr: TokenStream, item: TokenStream) -> TokenStream {
765 http1_0_macro(item)
766}
767
768/// Restricts function execution to HTTP/1.1 requests only.
769///
770/// This attribute macro ensures the decorated function only executes for HTTP/1.1
771/// protocol requests.
772///
773/// # Usage
774///
775/// ```rust
776/// use hyperlane::*;
777/// use hyperlane_macros::*;
778///
779/// #[http1_1]
780/// async fn handle_http11(ctx: Context) {
781/// // Handle HTTP/1.1 requests
782/// }
783/// ```
784///
785/// The macro takes no parameters and should be applied directly to async functions
786/// that accept a `Context` parameter.
787#[proc_macro_attribute]
788pub fn http1_1(_attr: TokenStream, item: TokenStream) -> TokenStream {
789 http1_1_macro(item)
790}
791
792/// Restricts function execution to HTTP/1.1 or higher protocol versions.
793///
794/// This attribute macro ensures the decorated function only executes for HTTP/1.1
795/// or newer protocol versions, including HTTP/2, HTTP/3, and future versions.
796///
797/// # Usage
798///
799/// ```rust
800/// use hyperlane::*;
801/// use hyperlane_macros::*;
802///
803/// #[http1_1_or_higher]
804/// async fn handle_modern_http(ctx: Context) {
805/// // Handle HTTP/1.1, HTTP/2, HTTP/3, etc.
806/// }
807/// ```
808///
809/// The macro takes no parameters and should be applied directly to async functions
810/// that accept a `Context` parameter.
811#[proc_macro_attribute]
812pub fn http1_1_or_higher(_attr: TokenStream, item: TokenStream) -> TokenStream {
813 http1_1_or_higher_macro(item)
814}
815
816/// Restricts function execution to HTTP/2 requests only.
817///
818/// This attribute macro ensures the decorated function only executes for HTTP/2
819/// protocol requests.
820///
821/// # Usage
822///
823/// ```rust
824/// use hyperlane::*;
825/// use hyperlane_macros::*;
826///
827/// #[http2]
828/// async fn handle_http2(ctx: Context) {
829/// // Handle HTTP/2 requests
830/// }
831/// ```
832///
833/// The macro takes no parameters and should be applied directly to async functions
834/// that accept a `Context` parameter.
835#[proc_macro_attribute]
836pub fn http2(_attr: TokenStream, item: TokenStream) -> TokenStream {
837 http2_macro(item)
838}
839
840/// Restricts function execution to HTTP/3 requests only.
841///
842/// This attribute macro ensures the decorated function only executes for HTTP/3
843/// protocol requests, the latest version of the HTTP protocol.
844///
845/// # Usage
846///
847/// ```rust
848/// use hyperlane::*;
849/// use hyperlane_macros::*;
850///
851/// #[http3]
852/// async fn handle_http3(ctx: Context) {
853/// // Handle HTTP/3 requests
854/// }
855/// ```
856///
857/// The macro takes no parameters and should be applied directly to async functions
858/// that accept a `Context` parameter.
859#[proc_macro_attribute]
860pub fn http3(_attr: TokenStream, item: TokenStream) -> TokenStream {
861 http3_macro(item)
862}
863
864/// Restricts function execution to TLS-encrypted requests only.
865///
866/// This attribute macro ensures the decorated function only executes for requests
867/// that use TLS/SSL encryption on the connection.
868///
869/// # Usage
870///
871/// ```rust
872/// use hyperlane::*;
873/// use hyperlane_macros::*;
874///
875/// #[tls]
876/// async fn handle_secure(ctx: Context) {
877/// // Handle TLS-encrypted requests only
878/// }
879/// ```
880///
881/// The macro takes no parameters and should be applied directly to async functions
882/// that accept a `Context` parameter.
883#[proc_macro_attribute]
884pub fn tls(_attr: TokenStream, item: TokenStream) -> TokenStream {
885 tls_macro(item)
886}
887
888/// Handles requests with unknown or non-standard HTTP methods.
889///
890/// This attribute macro configures the function to handle requests that use
891/// unrecognized or unsupported HTTP methods, providing a fallback for non-standard methods.
892///
893/// # Usage
894///
895/// ```rust
896/// use hyperlane::*;
897/// use hyperlane_macros::*;
898///
899/// #[filter_unknown_method]
900/// async fn handle_unknown_method(ctx: Context) {
901/// // Handle requests with unknown HTTP methods
902/// }
903/// ```
904///
905/// The macro takes no parameters and should be applied directly to async functions
906/// that accept a `Context` parameter.
907#[proc_macro_attribute]
908pub fn filter_unknown_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
909 filter_unknown_method_macro(item)
910}
911
912/// Handles requests with unknown or non-standard upgrade protocols.
913///
914/// This attribute macro configures the function to handle requests that specify
915/// unrecognized upgrade protocols, providing a fallback for non-standard upgrade request headers.
916///
917/// # Usage
918///
919/// ```rust
920/// use hyperlane::*;
921/// use hyperlane_macros::*;
922///
923/// #[filter_unknown_upgrade]
924/// async fn handle_unknown_upgrade(ctx: Context) {
925/// // Handle requests with unknown upgrade protocols
926/// }
927/// ```
928///
929/// The macro takes no parameters and should be applied directly to async functions
930/// that accept a `Context` parameter.
931#[proc_macro_attribute]
932pub fn filter_unknown_upgrade(_attr: TokenStream, item: TokenStream) -> TokenStream {
933 filter_unknown_upgrade_macro(item)
934}
935
936/// Handles requests with unknown or non-standard HTTP versions.
937///
938/// This attribute macro configures the function to handle requests that use
939/// unrecognized HTTP protocol versions, providing a fallback for non-standard versions.
940///
941/// # Usage
942///
943/// ```rust
944/// use hyperlane::*;
945/// use hyperlane_macros::*;
946///
947/// #[filter_unknown_version]
948/// async fn handle_unknown_version(ctx: Context) {
949/// // Handle requests with unknown HTTP versions
950/// }
951/// ```
952///
953/// The macro takes no parameters and should be applied directly to async functions
954/// that accept a `Context` parameter.
955#[proc_macro_attribute]
956pub fn filter_unknown_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
957 filter_unknown_version_macro(item)
958}
959
960/// Handles requests with any unknown characteristics.
961///
962/// This attribute macro combines filtering for unknown methods, upgrade protocols, and HTTP versions,
963/// providing comprehensive handling for requests with any unrecognized characteristics.
964///
965/// # Usage
966///
967/// ```rust
968/// use hyperlane::*;
969/// use hyperlane_macros::*;
970///
971/// #[filter_unknown]
972/// async fn handle_all_unknown(ctx: Context) {
973/// // Handle requests with any unknown characteristics
974/// }
975/// ```
976///
977/// The macro takes no parameters and should be applied directly to async functions
978/// that accept a `Context` parameter.
979#[proc_macro_attribute]
980pub fn filter_unknown(_attr: TokenStream, item: TokenStream) -> TokenStream {
981 filter_unknown_macro(item)
982}
983
984/// Restricts function execution to requests with a specific host.
985///
986/// This attribute macro ensures the decorated function only executes when the incoming request
987/// has a host header that matches the specified value. Requests with different or missing host headers will be filtered out.
988///
989/// # Usage
990///
991/// ```rust
992/// use hyperlane::*;
993/// use hyperlane_macros::*;
994///
995/// #[host("localhost")]
996/// async fn handle_example_com(ctx: Context) {
997/// // Function body for localhost requests
998/// }
999///
1000/// #[host("api.localhost")]
1001/// async fn handle_api_subdomain(ctx: Context) {
1002/// // Function body for api.localhost requests
1003/// }
1004/// ```
1005///
1006/// The macro accepts a string literal specifying the expected host value and should be
1007/// applied to async functions that accept a `Context` parameter.
1008#[proc_macro_attribute]
1009pub fn host(attr: TokenStream, item: TokenStream) -> TokenStream {
1010 host_macro(attr, item)
1011}
1012
1013/// Filters requests that have no host header.
1014///
1015/// This attribute macro ensures the decorated function only executes when the incoming request
1016/// has a host header present. Requests without a host header will be filtered out.
1017///
1018/// # Usage
1019///
1020/// ```rust
1021/// use hyperlane::*;
1022/// use hyperlane_macros::*;
1023///
1024/// #[host_filter("localhost")]
1025/// async fn handle_with_host(ctx: Context) {
1026/// // Function body for requests with host header
1027/// }
1028/// ```
1029///
1030/// The macro takes no parameters and should be applied directly to async functions
1031/// that accept a `Context` parameter.
1032#[proc_macro_attribute]
1033pub fn host_filter(attr: TokenStream, item: TokenStream) -> TokenStream {
1034 host_filter_macro(attr, item)
1035}
1036
1037/// Restricts function execution to requests with a specific referer.
1038///
1039/// This attribute macro ensures the decorated function only executes when the incoming request
1040/// has a referer header that matches the specified value. Requests with different or missing referer headers will be filtered out.
1041///
1042/// # Usage
1043///
1044/// ```rust
1045/// use hyperlane::*;
1046/// use hyperlane_macros::*;
1047///
1048/// #[referer("http://localhost")]
1049/// async fn handle_example_referer(ctx: Context) {
1050/// // Function body for requests from localhost
1051/// }
1052///
1053/// #[referer("https://api.localhost")]
1054/// async fn handle_api_referer(ctx: Context) {
1055/// // Function body for requests from api.localhost
1056/// }
1057/// ```
1058///
1059/// The macro accepts a string literal specifying the expected referer value and should be
1060/// applied to async functions that accept a `Context` parameter.
1061#[proc_macro_attribute]
1062pub fn referer(attr: TokenStream, item: TokenStream) -> TokenStream {
1063 referer_macro(attr, item)
1064}
1065
1066/// Filters requests that have a specific referer header.
1067///
1068/// This attribute macro ensures the decorated function only executes when the incoming request
1069/// does not have a referer header that matches the specified value. Requests with the matching referer header will be filtered out.
1070///
1071/// # Usage
1072///
1073/// ```rust
1074/// use hyperlane::*;
1075/// use hyperlane_macros::*;
1076///
1077/// #[referer_filter("http://localhost")]
1078/// async fn handle_without_spam_referer(ctx: Context) {
1079/// // Function body for requests not from localhost
1080/// }
1081/// ```
1082///
1083/// The macro accepts a string literal specifying the referer value to filter out and should be
1084/// applied to async functions that accept a `Context` parameter.
1085#[proc_macro_attribute]
1086pub fn referer_filter(attr: TokenStream, item: TokenStream) -> TokenStream {
1087 referer_filter_macro(attr, item)
1088}
1089
1090/// Executes a specified function before the main handler function.
1091///
1092/// This attribute macro configures a pre-execution hook that runs before the main function logic.
1093/// The specified hook function will be called first, followed by the main function execution.
1094///
1095/// # Usage
1096///
1097/// ```rust
1098/// use hyperlane::*;
1099/// use hyperlane_macros::*;
1100///
1101/// #[get]
1102/// async fn pre_handler(ctx: Context) {
1103/// // Pre-execution logic
1104/// }
1105///
1106/// #[pre_hook(pre_handler)]
1107/// async fn main_handler(ctx: Context) {
1108/// // Main function logic (runs after pre_handler)
1109/// }
1110/// ```
1111///
1112/// The macro accepts a function name as parameter. Both the hook function and main function
1113/// must accept a `Context` parameter. Avoid combining this macro with other macros on the
1114/// same function to prevent macro expansion conflicts.
1115#[proc_macro_attribute]
1116pub fn pre_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
1117 pre_hook_macro(attr, item)
1118}
1119
1120/// Executes a specified function after the main handler function.
1121///
1122/// This attribute macro configures a post-execution hook that runs after the main function logic.
1123/// The main function will execute first, followed by the specified hook function.
1124///
1125/// # Usage
1126///
1127/// ```rust
1128/// use hyperlane::*;
1129/// use hyperlane_macros::*;
1130///
1131/// #[send]
1132/// async fn post_handler(ctx: Context) {
1133/// // Post-execution logic
1134/// }
1135///
1136/// #[post_hook(post_handler)]
1137/// async fn main_handler(ctx: Context) {
1138/// // Main function logic (runs before post_handler)
1139/// }
1140/// ```
1141///
1142/// The macro accepts a function name as parameter. Both the hook function and main function
1143/// must accept a `Context` parameter. Avoid combining this macro with other macros on the
1144/// same function to prevent macro expansion conflicts.
1145#[proc_macro_attribute]
1146pub fn post_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
1147 post_hook_macro(attr, item)
1148}
1149
1150/// Extracts the raw request body into a specified variable.
1151///
1152/// This attribute macro extracts the raw request body content into a variable
1153/// with the fixed type `RequestBody`. The body content is not parsed or deserialized.
1154///
1155/// # Usage
1156///
1157/// ```rust
1158/// use hyperlane::*;
1159/// use hyperlane_macros::*;
1160///
1161/// #[request_body(raw_body)]
1162/// async fn handle_raw_body(ctx: Context) {
1163/// // Use the raw request body
1164/// let body_content = raw_body;
1165/// }
1166/// ```
1167///
1168/// The macro accepts only a variable name. The variable will be available
1169/// in the function scope as a `RequestBody` type.
1170#[proc_macro_attribute]
1171pub fn request_body(attr: TokenStream, item: TokenStream) -> TokenStream {
1172 request_body_macro(attr, item)
1173}
1174
1175/// Parses the request body as JSON into a specified variable and type.
1176///
1177/// This attribute macro extracts and deserializes the request body content as JSON into a variable
1178/// with the specified type. The body content is parsed as JSON using serde.
1179///
1180/// # Usage
1181///
1182/// ```rust
1183/// use hyperlane::*;
1184/// use hyperlane_macros::*;
1185/// use serde::Deserialize;
1186///
1187/// #[derive(Deserialize, Clone)]
1188/// struct UserData {
1189/// name: String,
1190/// age: u32,
1191/// }
1192///
1193/// #[request_body_json(user_data: UserData)]
1194/// async fn handle_user(ctx: Context) {
1195/// if let Ok(data) = user_data {
1196/// // Use the parsed user data
1197/// }
1198/// }
1199/// ```
1200///
1201/// The macro accepts a variable name and type in the format `variable_name: Type`.
1202/// The variable will be available in the function scope as a `Result<Type, JsonError>`.
1203#[proc_macro_attribute]
1204pub fn request_body_json(attr: TokenStream, item: TokenStream) -> TokenStream {
1205 request_body_json_macro(attr, item)
1206}
1207
1208/// Extracts a specific attribute value into a variable.
1209///
1210/// This attribute macro retrieves a specific attribute by key and makes it available
1211/// as a typed variable from the request context.
1212///
1213/// # Usage
1214///
1215/// ```rust
1216/// use hyperlane::*;
1217/// use hyperlane_macros::*;
1218/// use serde::Deserialize;
1219///
1220/// const USER_KEY: &str = "user_data";
1221///
1222/// #[derive(Deserialize, Clone)]
1223/// struct User {
1224/// id: u64,
1225/// name: String,
1226/// }
1227///
1228/// #[attribute(USER_KEY => user: User)]
1229/// async fn handle_with_attribute(ctx: Context) {
1230/// if let Some(user_data) = user {
1231/// // Use the extracted attribute
1232/// }
1233/// }
1234/// ```
1235///
1236/// The macro accepts a key-to-variable mapping in the format `key => variable_name: Type`.
1237/// The variable will be available as an `Option<Type>` in the function scope.
1238#[proc_macro_attribute]
1239pub fn attribute(attr: TokenStream, item: TokenStream) -> TokenStream {
1240 attribute_macro(attr, item)
1241}
1242
1243/// Extracts all attributes into a HashMap variable.
1244///
1245/// This attribute macro retrieves all available attributes from the request context
1246/// and makes them available as a HashMap for comprehensive attribute access.
1247///
1248/// # Usage
1249///
1250/// ```rust
1251/// use hyperlane::*;
1252/// use hyperlane_macros::*;
1253///
1254/// #[attributes(all_attrs)]
1255/// async fn handle_with_all_attributes(ctx: Context) {
1256/// for (key, value) in all_attrs {
1257/// // Process each attribute
1258/// }
1259/// }
1260/// ```
1261///
1262/// The macro accepts a variable name that will contain a HashMap of all attributes.
1263/// The variable will be available as a HashMap in the function scope.
1264#[proc_macro_attribute]
1265pub fn attributes(attr: TokenStream, item: TokenStream) -> TokenStream {
1266 attributes_macro(attr, item)
1267}
1268
1269/// Extracts a specific route parameter into a variable.
1270///
1271/// This attribute macro retrieves a specific route parameter by key and makes it
1272/// available as a variable. Route parameters are extracted from the URL path segments.
1273///
1274/// # Usage
1275///
1276/// ```rust
1277/// use hyperlane::*;
1278/// use hyperlane_macros::*;
1279///
1280/// // For route like "/users/{id}"
1281/// #[route_param("id" => user_id)]
1282/// async fn get_user(ctx: Context) {
1283/// if let Some(id) = user_id {
1284/// // Use the route parameter
1285/// }
1286/// }
1287/// ```
1288///
1289/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
1290/// The variable will be available as an `Option<String>` in the function scope.
1291#[proc_macro_attribute]
1292pub fn route_param(attr: TokenStream, item: TokenStream) -> TokenStream {
1293 route_param_macro(attr, item)
1294}
1295
1296/// Extracts all route parameters into a collection variable.
1297///
1298/// This attribute macro retrieves all available route parameters from the URL path
1299/// and makes them available as a collection for comprehensive route parameter access.
1300///
1301/// # Usage
1302///
1303/// ```rust
1304/// use hyperlane::*;
1305/// use hyperlane_macros::*;
1306///
1307/// // For route like "/users/{id}/posts/{post_id}"
1308/// #[route_params(params)]
1309/// async fn handle_nested_route(ctx: Context) {
1310/// for (key, value) in params {
1311/// // Process each route parameter
1312/// }
1313/// }
1314/// ```
1315///
1316/// The macro accepts a variable name that will contain all route parameters.
1317/// The variable will be available as a collection in the function scope.
1318#[proc_macro_attribute]
1319pub fn route_params(attr: TokenStream, item: TokenStream) -> TokenStream {
1320 route_params_macro(attr, item)
1321}
1322
1323/// Extracts a specific request query parameter into a variable.
1324///
1325/// This attribute macro retrieves a specific request query parameter by key and makes it
1326/// available as a variable. Query parameters are extracted from the URL request query string.
1327///
1328/// # Usage
1329///
1330/// ```rust
1331/// use hyperlane::*;
1332/// use hyperlane_macros::*;
1333///
1334/// // For URL like "/search?q=rust&limit=10"
1335/// #[request_query("q" => search_term)]
1336/// async fn search(ctx: Context) {
1337/// if let Some(term) = search_term {
1338/// // Use the request query parameter
1339/// }
1340/// }
1341/// ```
1342///
1343/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
1344/// The variable will be available as an `Option<String>` in the function scope.
1345#[proc_macro_attribute]
1346pub fn request_query(attr: TokenStream, item: TokenStream) -> TokenStream {
1347 request_query_macro(attr, item)
1348}
1349
1350/// Extracts all request query parameters into a collection variable.
1351///
1352/// This attribute macro retrieves all available request query parameters from the URL request query string
1353/// and makes them available as a collection for comprehensive request query parameter access.
1354///
1355/// # Usage
1356///
1357/// ```rust
1358/// use hyperlane::*;
1359/// use hyperlane_macros::*;
1360///
1361/// // For URL like "/search?q=rust&limit=10&sort=date"
1362/// #[request_querys(all_params)]
1363/// async fn search_with_params(ctx: Context) {
1364/// for (key, value) in all_params {
1365/// // Process each request query parameter
1366/// }
1367/// }
1368/// ```
1369///
1370/// The macro accepts a variable name that will contain all request query parameters.
1371/// The variable will be available as a collection in the function scope.
1372#[proc_macro_attribute]
1373pub fn request_querys(attr: TokenStream, item: TokenStream) -> TokenStream {
1374 request_querys_macro(attr, item)
1375}
1376
1377/// Extracts a specific HTTP request header into a variable.
1378///
1379/// This attribute macro retrieves a specific HTTP request header by name and makes it
1380/// available as a variable. Header values are extracted from the request request headers collection.
1381///
1382/// # Usage
1383///
1384/// ```rust
1385/// use hyperlane::*;
1386/// use hyperlane_macros::*;
1387///
1388/// #[request_header(HOST => host_request_header)]
1389/// async fn handle_with_host(ctx: Context) {
1390/// if let Some(host) = host_request_header {
1391/// // Use the host request_header value
1392/// }
1393/// }
1394///
1395/// #[request_header("Content-Type" => content_type)]
1396/// async fn handle_with_content_type(ctx: Context) {
1397/// if let Some(ct) = content_type {
1398/// // Use the content type request_header
1399/// }
1400/// }
1401/// ```
1402///
1403/// The macro accepts a request header name-to-variable mapping in the format `HEADER_NAME => variable_name`
1404/// or `"Header-Name" => variable_name`. The variable will be available as an `Option<String>`.
1405#[proc_macro_attribute]
1406pub fn request_header(attr: TokenStream, item: TokenStream) -> TokenStream {
1407 request_header_macro(attr, item)
1408}
1409
1410/// Extracts all HTTP request headers into a collection variable.
1411///
1412/// This attribute macro retrieves all available HTTP request headers from the request
1413/// and makes them available as a collection for comprehensive request header access.
1414///
1415/// # Usage
1416///
1417/// ```rust
1418/// use hyperlane::*;
1419/// use hyperlane_macros::*;
1420///
1421/// #[request_headers(all_request_headers)]
1422/// async fn handle_with_all_request_headers(ctx: Context) {
1423/// for (name, value) in all_request_headers {
1424/// // Process each request_header
1425/// }
1426/// }
1427/// ```
1428///
1429/// The macro accepts a variable name that will contain all HTTP request headers.
1430/// The variable will be available as a collection in the function scope.
1431#[proc_macro_attribute]
1432pub fn request_headers(attr: TokenStream, item: TokenStream) -> TokenStream {
1433 request_headers_macro(attr, item)
1434}
1435
1436/// Extracts a specific cookie value or all cookies into a variable.
1437///
1438/// This attribute macro supports two syntaxes:
1439/// 1. `cookie(key => variable_name)` - Extract a specific cookie value by key
1440/// 2. `cookie(variable_name)` - Extract all cookies as a raw string
1441///
1442/// # Usage
1443///
1444/// ```rust
1445/// use hyperlane::*;
1446/// use hyperlane_macros::*;
1447///
1448/// #[request_cookie("session_id" => session_cookie_opt)]
1449/// async fn handle_with_session(ctx: Context) {
1450/// if let Some(session) = session_cookie_opt {
1451/// // Use the session cookie value
1452/// }
1453/// }
1454/// ```
1455///
1456/// For specific cookie extraction, the variable will be available as `Option<String>`.
1457/// For all cookies extraction, the variable will be available as `String`.
1458#[proc_macro_attribute]
1459pub fn request_cookie(attr: TokenStream, item: TokenStream) -> TokenStream {
1460 request_cookie_macro(attr, item)
1461}
1462
1463/// Extracts all cookies as a raw string into a variable.
1464///
1465/// This attribute macro retrieves the entire Cookie header from the request and makes it
1466/// available as a String variable. If no Cookie header is present, an empty string is used.
1467///
1468/// # Usage
1469///
1470/// ```rust
1471/// use hyperlane::*;
1472/// use hyperlane_macros::*;
1473///
1474/// #[request_cookies(cookie_value)]
1475/// async fn handle_with_cookies(ctx: Context) {
1476/// // Use the cookie value
1477/// if !cookie_value.is_empty() {
1478/// // Process cookie data
1479/// }
1480/// }
1481/// ```
1482///
1483/// The macro accepts a variable name that will contain the Cookie header value.
1484/// The variable will be available as a String in the function scope.
1485#[proc_macro_attribute]
1486pub fn request_cookies(attr: TokenStream, item: TokenStream) -> TokenStream {
1487 request_cookies_macro(attr, item)
1488}
1489
1490/// Extracts the HTTP request version into a variable.
1491///
1492/// This attribute macro retrieves the HTTP version from the request and makes it
1493/// available as a variable. The version represents the HTTP protocol version used.
1494///
1495/// # Usage
1496///
1497/// ```rust
1498/// use hyperlane::*;
1499/// use hyperlane_macros::*;
1500///
1501/// #[request_version(http_version)]
1502/// async fn handle_with_version(ctx: Context) {
1503/// // Use the HTTP version
1504/// }
1505/// ```
1506///
1507/// The macro accepts a variable name that will contain the HTTP request version.
1508/// The variable will be available as a RequestVersion type in the function scope.
1509#[proc_macro_attribute]
1510pub fn request_version(attr: TokenStream, item: TokenStream) -> TokenStream {
1511 request_version_macro(attr, item)
1512}
1513
1514/// Extracts the HTTP request path into a variable.
1515///
1516/// This attribute macro retrieves the request path from the HTTP request and makes it
1517/// available as a variable. The path represents the URL path portion of the request.
1518///
1519/// # Usage
1520///
1521/// ```rust
1522/// use hyperlane::*;
1523/// use hyperlane_macros::*;
1524///
1525/// #[request_path(request_path)]
1526/// async fn handle_with_path(ctx: Context) {
1527/// // Use the request path
1528/// if request_path.starts_with("/api/") {
1529/// // Handle API requests
1530/// }
1531/// }
1532/// ```
1533///
1534/// The macro accepts a variable name that will contain the HTTP request path.
1535/// The variable will be available as a RequestPath type in the function scope.
1536#[proc_macro_attribute]
1537pub fn request_path(attr: TokenStream, item: TokenStream) -> TokenStream {
1538 request_path_macro(attr, item)
1539}
1540
1541/// Creates a new instance of a specified type with a given variable name.
1542///
1543/// This attribute macro generates an instance initialization at the beginning of the function.
1544///
1545/// # Usage
1546///
1547/// ```rust
1548/// use hyperlane::*;
1549/// use hyperlane_macros::*;
1550///
1551/// #[hyperlane(Server => server)]
1552/// #[tokio::main]
1553/// async fn main() {
1554/// // `server` is now available as: `let server: Server = Server::new().await;`
1555/// // The function body can now use `server`.
1556/// }
1557/// ```
1558///
1559/// The macro accepts a `Type => variable_name` pair.
1560/// The variable will be available as an instance of the specified type in the function scope.
1561#[proc_macro_attribute]
1562pub fn hyperlane(attr: TokenStream, item: TokenStream) -> TokenStream {
1563 hyperlane_macro(attr, item)
1564}