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