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