Skip to main content

axum_wire_macros/
lib.rs

1//! Proc macros for `axum-wire`.
2//!
3//! This crate provides:
4//! - `#[derive(Component)]`
5//! - `#[wire_actions]`
6//! - `#[on(...)]`
7//! - `html!`
8//!
9//! Most users should depend on `axum-wire` directly and import the macros from
10//! there rather than using this crate on its own.
11
12use proc_macro::TokenStream;
13use quote::quote;
14use syn::{parse_macro_input, DeriveInput, ImplItem, ItemImpl};
15
16mod rsx;
17
18// ---------------------------------------------------------------------------
19// #[derive(Component)]
20// ---------------------------------------------------------------------------
21
22#[proc_macro_derive(Component, attributes(component, url, locked, layout, on, __wire_on))]
23pub fn derive_component(input: TokenStream) -> TokenStream {
24    let input = parse_macro_input!(input as DeriveInput);
25    let name = &input.ident;
26    let name_str = name.to_string();
27    let wire_name = pascal_to_kebab(&name_str);
28
29    // Parse #[url] attributes on struct fields
30    let url_fields = parse_url_fields(&input);
31    // Parse #[locked] attributes on struct fields
32    let locked_fields = parse_locked_fields(&input);
33    // Parse #[layout("name")] attribute on the struct
34    let layout_name = parse_layout_attr(&input);
35    // Parse #[on("event")] attributes on the component
36    let component_event_listeners = parse_component_event_listeners(&input);
37
38    let url_fields_count = url_fields.len();
39    let url_fields_tokens = url_fields.iter().map(|uf| {
40        let field_name = &uf.field_name;
41        let query_name = &uf.query_name;
42        let history = uf.history;
43        let keep = uf.keep;
44        quote! {
45            ::axum_wire::UrlFieldMeta {
46                field_name: #field_name,
47                query_name: #query_name,
48                history: #history,
49                keep: #keep,
50            }
51        }
52    });
53
54    let locked_fields_count = locked_fields.len();
55    let locked_fields_tokens = locked_fields.iter().map(|name| {
56        quote! { #name }
57    });
58
59    let layout_name_impl = match &layout_name {
60        Some(name) => quote! {
61            fn layout_name() -> Option<&'static str> {
62                Some(#name)
63            }
64        },
65        None => quote! {},
66    };
67
68    let layout_name_const = match &layout_name {
69        Some(name) => quote! { Some(#name) },
70        None => quote! { None },
71    };
72
73    let component_event_listeners_count = component_event_listeners.len();
74    let component_event_listener_tokens = component_event_listeners.iter().map(|event| {
75        quote! {
76            ::axum_wire::EventListenerMeta {
77                event: #event,
78                action: "$refresh",
79            }
80        }
81    });
82
83    let expanded = quote! {
84        impl #name {
85            /// Static array of `#[url]` field metadata, generated by `#[derive(Component)]`.
86            const __WIRE_URL_FIELDS: [::axum_wire::UrlFieldMeta; #url_fields_count] = [#(#url_fields_tokens),*];
87            /// Static array of `#[locked]` field names, generated by `#[derive(Component)]`.
88            const __WIRE_LOCKED_FIELDS: [&'static str; #locked_fields_count] = [#(#locked_fields_tokens),*];
89            /// Layout name from `#[layout("name")]`, generated by `#[derive(Component)]`.
90            const __WIRE_LAYOUT: Option<&'static str> = #layout_name_const;
91            /// Component-level listeners from `#[on("event")]`, generated by `#[derive(Component)]`.
92            const __WIRE_COMPONENT_EVENT_LISTENERS: [::axum_wire::EventListenerMeta; #component_event_listeners_count] = [#(#component_event_listener_tokens),*];
93        }
94
95        impl ::axum_wire::ComponentMeta for #name {
96            fn component_name() -> &'static str {
97                #wire_name
98            }
99
100            fn url_fields() -> &'static [::axum_wire::UrlFieldMeta] {
101                &#name::__WIRE_URL_FIELDS
102            }
103
104            fn locked_fields() -> &'static [&'static str] {
105                &#name::__WIRE_LOCKED_FIELDS
106            }
107
108            fn event_listeners() -> &'static [::axum_wire::EventListenerMeta] {
109                &#name::__WIRE_COMPONENT_EVENT_LISTENERS
110            }
111
112            #layout_name_impl
113        }
114    };
115
116    TokenStream::from(expanded)
117}
118
119struct UrlFieldInfo {
120    field_name: String,
121    query_name: String,
122    history: bool,
123    keep: bool,
124}
125
126fn parse_url_fields(input: &DeriveInput) -> Vec<UrlFieldInfo> {
127    let mut url_fields = Vec::new();
128
129    let fields = match &input.data {
130        syn::Data::Struct(data) => match &data.fields {
131            syn::Fields::Named(named) => &named.named,
132            _ => return url_fields,
133        },
134        _ => return url_fields,
135    };
136
137    for field in fields {
138        for attr in &field.attrs {
139            if !attr.path().is_ident("url") {
140                continue;
141            }
142
143            let field_name = field
144                .ident
145                .as_ref()
146                .expect("#[url] requires named fields")
147                .to_string();
148
149            let mut query_name = field_name.clone();
150            let mut history = false;
151            let mut keep = false;
152
153            // Parse #[url] or #[url(as = "q", history, keep)]
154            if let syn::Meta::List(_) = &attr.meta {
155                let _ = attr.parse_nested_meta(|meta| {
156                    if meta.path.is_ident("as") {
157                        let value = meta.value()?;
158                        let lit: syn::LitStr = value.parse()?;
159                        query_name = lit.value();
160                    } else if meta.path.is_ident("history") {
161                        history = true;
162                    } else if meta.path.is_ident("keep") {
163                        keep = true;
164                    }
165                    Ok(())
166                });
167            }
168
169            url_fields.push(UrlFieldInfo {
170                field_name,
171                query_name,
172                history,
173                keep,
174            });
175        }
176    }
177
178    url_fields
179}
180
181fn parse_locked_fields(input: &DeriveInput) -> Vec<String> {
182    let mut locked_fields = Vec::new();
183
184    let fields = match &input.data {
185        syn::Data::Struct(data) => match &data.fields {
186            syn::Fields::Named(named) => &named.named,
187            _ => return locked_fields,
188        },
189        _ => return locked_fields,
190    };
191
192    for field in fields {
193        let has_locked = field.attrs.iter().any(|a| a.path().is_ident("locked"));
194        if has_locked {
195            let field_name = field
196                .ident
197                .as_ref()
198                .expect("#[locked] requires named fields")
199                .to_string();
200            locked_fields.push(field_name);
201        }
202    }
203
204    locked_fields
205}
206
207fn parse_component_event_listeners(input: &DeriveInput) -> Vec<String> {
208    let mut events = Vec::new();
209
210    for attr in &input.attrs {
211        if !attr.path().is_ident("on") && !attr.path().is_ident("__wire_on") {
212            continue;
213        }
214
215        let event_name = attr
216            .parse_args::<syn::LitStr>()
217            .map(|lit| lit.value())
218            .ok()
219            .or_else(|| {
220                attr.parse_args::<proc_macro2::TokenStream>()
221                    .ok()
222                    .map(|ts| ts.to_string().replace(' ', ""))
223            });
224
225        if let Some(event) = event_name {
226            events.push(event);
227        }
228    }
229
230    events
231}
232
233/// Parse `#[layout("name")]` attribute on the struct.
234fn parse_layout_attr(input: &DeriveInput) -> Option<String> {
235    for attr in &input.attrs {
236        if !attr.path().is_ident("layout") {
237            continue;
238        }
239        // #[layout("name")] — parse the string literal
240        if let Ok(lit) = attr.parse_args::<syn::LitStr>() {
241            return Some(lit.value());
242        }
243    }
244    None
245}
246
247pub(crate) fn pascal_to_kebab(s: &str) -> String {
248    let mut result = String::new();
249    for (i, c) in s.chars().enumerate() {
250        if c.is_uppercase() {
251            if i > 0 {
252                result.push('-');
253            }
254            result.push(c.to_ascii_lowercase());
255        } else {
256            result.push(c);
257        }
258    }
259    result
260}
261
262// ---------------------------------------------------------------------------
263// #[wire_actions]
264// ---------------------------------------------------------------------------
265
266#[proc_macro_attribute]
267pub fn wire_actions(_attr: TokenStream, item: TokenStream) -> TokenStream {
268    let input = parse_macro_input!(item as ItemImpl);
269    let self_ty = &input.self_ty;
270
271    let type_name = quote!(#self_ty).to_string();
272    let wire_name = pascal_to_kebab(&type_name);
273
274    let mut action_names: Vec<String> = Vec::new();
275    let mut action_idents: Vec<proc_macro2::Ident> = Vec::new();
276    let mut action_renderless: Vec<bool> = Vec::new();
277    let mut action_is_async: Vec<bool> = Vec::new();
278    let mut action_payload_tys: Vec<Option<syn::Type>> = Vec::new();
279    let mut action_payload_from_detail: Vec<bool> = Vec::new();
280    let mut event_listeners: Vec<(String, String)> = Vec::new();
281    let mut has_render = false;
282    let mut has_mount = false;
283    let mut render_is_async = false;
284    let mut mount_is_async = false;
285    let mut mount_has_ctx = false;
286
287    for item in &input.items {
288        if let ImplItem::Fn(method) = item {
289            let sig = &method.sig;
290            let method_name = sig.ident.to_string();
291
292            match method_name.as_str() {
293                "render" => {
294                    has_render = true;
295                    render_is_async = sig.asyncness.is_some();
296                }
297                "mount" => {
298                    has_mount = true;
299                    mount_is_async = sig.asyncness.is_some();
300                    // Check if mount takes a WireContext parameter
301                    // mount() or mount(ctx: WireContext)
302                    mount_has_ctx = sig.inputs.iter().any(|arg| {
303                        if let syn::FnArg::Typed(pat_type) = arg {
304                            let ty_str = quote!(#pat_type).to_string();
305                            ty_str.contains("WireContext")
306                        } else {
307                            false
308                        }
309                    });
310                }
311                _ => {
312                    if let Some(syn::FnArg::Receiver(receiver)) = sig.inputs.first() {
313                        if receiver.mutability.is_some() {
314                            let is_renderless =
315                                method.attrs.iter().any(|a| a.path().is_ident("renderless"));
316                            let is_async = sig.asyncness.is_some();
317                            let mut is_on_listener = false;
318                            action_names.push(method_name);
319                            action_idents.push(sig.ident.clone());
320                            action_renderless.push(is_renderless);
321                            action_is_async.push(is_async);
322
323                            for attr in &method.attrs {
324                                if !attr.path().is_ident("on") {
325                                    continue;
326                                }
327
328                                let event_name = attr
329                                    .parse_args::<syn::LitStr>()
330                                    .map(|lit| lit.value())
331                                    .ok()
332                                    .or_else(|| {
333                                        attr.parse_args::<proc_macro2::TokenStream>()
334                                            .ok()
335                                            .map(|ts| ts.to_string().replace(' ', ""))
336                                    });
337
338                                if let Some(event) = event_name {
339                                    is_on_listener = true;
340                                    event_listeners.push((event, sig.ident.to_string()));
341                                }
342                            }
343
344                            let payload_ty = sig.inputs.iter().nth(1).and_then(|arg| match arg {
345                                syn::FnArg::Typed(pat_type) => Some((*pat_type.ty).clone()),
346                                _ => None,
347                            });
348
349                            action_payload_tys.push(payload_ty);
350                            action_payload_from_detail.push(is_on_listener);
351                        }
352                    }
353                }
354            }
355        }
356    }
357
358    if !has_render {
359        return syn::Error::new_spanned(
360            &input.self_ty,
361            "#[wire_actions] requires a `fn render(&self) -> String` method",
362        )
363        .to_compile_error()
364        .into();
365    }
366
367    // Check if any actions are async — if so, call_action must be async
368    let any_action_async = action_is_async.iter().any(|a| *a);
369
370    // Generate mount() if not provided
371    let mount_impl = if has_mount {
372        quote! {}
373    } else {
374        quote! {
375            fn mount() -> Self {
376                Self::default()
377            }
378        }
379    };
380
381    // Generate dispatch arms for call_action
382    let dispatch_arms: Vec<_> = action_names
383        .iter()
384        .zip(action_idents.iter())
385        .zip(action_renderless.iter())
386        .zip(action_is_async.iter())
387        .zip(action_payload_tys.iter())
388        .zip(action_payload_from_detail.iter())
389        .map(|(((((name, ident), renderless), is_async), payload_ty), payload_from_detail)| {
390            let skip_render = if *renderless {
391                quote! { ::axum_wire::set_skip_render(); }
392            } else {
393                quote! {}
394            };
395
396            let payload_expr = if *payload_from_detail {
397                quote! {
398                    _payload
399                        .get("detail")
400                        .cloned()
401                        .unwrap_or(::axum_wire::serde_json::Value::Null)
402                }
403            } else {
404                quote! {
405                    _payload
406                        .get("args")
407                        .and_then(|args| args.as_array())
408                        .and_then(|args| args.first().cloned())
409                        .unwrap_or_else(|| _payload.clone())
410                }
411            };
412
413            let invoke = if let Some(ty) = payload_ty {
414                if *is_async {
415                    quote! {
416                        let __wire_payload: #ty = ::axum_wire::serde_json::from_value(#payload_expr)
417                            .map_err(|e| ::axum_wire::WireError::Deserialization(e.to_string()))?;
418                        self.#ident(__wire_payload).await;
419                    }
420                } else {
421                    quote! {
422                        let __wire_payload: #ty = ::axum_wire::serde_json::from_value(#payload_expr)
423                            .map_err(|e| ::axum_wire::WireError::Deserialization(e.to_string()))?;
424                        self.#ident(__wire_payload);
425                    }
426                }
427            } else if *is_async {
428                quote! {
429                    self.#ident().await;
430                }
431            } else {
432                quote! {
433                    ::axum_wire::subsecond::call(|| self.#ident());
434                }
435            };
436
437            quote! {
438                #name => {
439                    #skip_render
440                    #invoke
441                }
442            }
443        })
444        .collect();
445
446    // render call: .await if async, direct call if sync
447    // subsecond::call wraps sync calls for hot-patching (no-op in release).
448    let render_call = if render_is_async {
449        quote! { component.render().await }
450    } else {
451        quote! { ::axum_wire::subsecond::call(|| component.render()) }
452    };
453
454    // mount call: .await if async, direct call if sync
455    // If mount takes a WireContext param, pass __wire_ctx
456    let mount_call = match (mount_is_async, mount_has_ctx) {
457        (true, true) => quote! { #self_ty::mount(__wire_ctx.clone()).await },
458        (true, false) => quote! { #self_ty::mount().await },
459        (false, true) => {
460            quote! { ::axum_wire::subsecond::call(|| #self_ty::mount(__wire_ctx.clone())) }
461        }
462        (false, false) => quote! { ::axum_wire::subsecond::call(|| #self_ty::mount()) },
463    };
464
465    // Strip #[renderless] attributes from the impl block so rustc doesn't error
466    let mut cleaned_input = input.clone();
467    for item in &mut cleaned_input.items {
468        if let ImplItem::Fn(method) = item {
469            method
470                .attrs
471                .retain(|a| !a.path().is_ident("renderless") && !a.path().is_ident("on"));
472        }
473    }
474
475    let event_listeners_count = event_listeners.len();
476    let event_listener_tokens = event_listeners.iter().map(|(event, action)| {
477        quote! {
478            ::axum_wire::EventListenerMeta {
479                event: #event,
480                action: #action,
481            }
482        }
483    });
484
485    // call_action: if any action is async, the whole method must be async
486    // and return a BoxFuture. Otherwise, keep it sync.
487    let call_action_method = if any_action_async {
488        quote! {
489            /// Dispatch an action by name. Returns collected side-effects.
490            /// Async because one or more actions are async.
491            pub async fn call_action(&mut self, action: &str, _payload: ::axum_wire::serde_json::Value) -> Result<::axum_wire::ActionEffects, ::axum_wire::WireError> {
492                let __scope = ::axum_wire::ActionScope::begin();
493                match action {
494                    "$refresh" => {},
495                    #(#dispatch_arms,)*
496                    _ => {
497                        drop(__scope);
498                        return Err(::axum_wire::WireError::UnknownAction(action.to_string()));
499                    },
500                }
501                Ok(__scope.finish())
502            }
503        }
504    } else {
505        quote! {
506            /// Dispatch an action by name. Returns collected side-effects.
507            pub fn call_action(&mut self, action: &str, _payload: ::axum_wire::serde_json::Value) -> Result<::axum_wire::ActionEffects, ::axum_wire::WireError> {
508                let __scope = ::axum_wire::ActionScope::begin();
509                match action {
510                    "$refresh" => {},
511                    #(#dispatch_arms,)*
512                    _ => {
513                        drop(__scope);
514                        return Err(::axum_wire::WireError::UnknownAction(action.to_string()));
515                    },
516                }
517                Ok(__scope.finish())
518            }
519        }
520    };
521
522    // In the update factory closure, call_action may or may not be async
523    let call_action_invoke = if any_action_async {
524        quote! { component.call_action(action, payload).await? }
525    } else {
526        quote! { component.call_action(action, payload)? }
527    };
528
529    let expanded = quote! {
530        #cleaned_input
531
532        impl #self_ty {
533            #mount_impl
534
535            #call_action_method
536
537            /// Get the current `WireContext` (available in render and actions).
538            pub fn ctx(&self) -> ::axum_wire::WireContext {
539                ::axum_wire::get_wire_ctx()
540            }
541
542            /// Queue a JavaScript snippet to execute on the client after this action.
543            /// `$wire` is available in the JS context.
544            pub fn js(&self, code: &str) {
545                ::axum_wire::push_js(code.to_string());
546            }
547
548            /// Dispatch a browser event from this component root.
549            pub fn dispatch(&self, name: &str) {
550                ::axum_wire::dispatch_event(name.to_string(), None);
551            }
552
553            /// Dispatch a browser event with a JSON detail payload.
554            pub fn dispatch_with<T: ::serde::Serialize>(&self, name: &str, detail: T) {
555                if let Ok(value) = ::axum_wire::serde_json::to_value(detail) {
556                    ::axum_wire::dispatch_event(name.to_string(), Some(value));
557                }
558            }
559
560            /// Dispatch a browser event to this component root only.
561            pub fn dispatch_self(&self, name: &str) {
562                ::axum_wire::dispatch_event_targeted(name.to_string(), None, Some(::std::string::String::from("self")));
563            }
564
565            /// Dispatch a browser event with payload to this component root only.
566            pub fn dispatch_self_with<T: ::serde::Serialize>(&self, name: &str, detail: T) {
567                if let Ok(value) = ::axum_wire::serde_json::to_value(detail) {
568                    ::axum_wire::dispatch_event_targeted(name.to_string(), Some(value), Some(::std::string::String::from("self")));
569                }
570            }
571
572            /// Dispatch a browser event to all mounted components with the given wire name.
573            pub fn dispatch_to(&self, component: &str, name: &str) {
574                ::axum_wire::dispatch_event_targeted(name.to_string(), None, Some(::std::format!("to:{component}")));
575            }
576
577            /// Dispatch a browser event with payload to all mounted components with the given wire name.
578            pub fn dispatch_to_with<T: ::serde::Serialize>(&self, component: &str, name: &str, detail: T) {
579                if let Ok(value) = ::axum_wire::serde_json::to_value(detail) {
580                    ::axum_wire::dispatch_event_targeted(name.to_string(), Some(value), Some(::std::format!("to:{component}")));
581                }
582            }
583
584            /// Skip re-rendering after this action. Only the updated snapshot is sent back.
585            pub fn skip_render(&self) {
586                ::axum_wire::set_skip_render();
587            }
588
589            /// Redirect the client to a URL (full page navigation). Implies skip_render.
590            pub fn redirect(&self, url: &str) {
591                ::axum_wire::set_redirect(url.to_string(), false);
592            }
593
594            /// Redirect using wire:navigate (SPA-style, no full reload). Implies skip_render.
595            pub fn redirect_navigate(&self, url: &str) {
596                ::axum_wire::set_redirect(url.to_string(), true);
597            }
598
599            /// Listener metadata generated from `#[on("event")]` action attributes.
600            const __WIRE_EVENT_LISTENERS: [::axum_wire::EventListenerMeta; #event_listeners_count] = [#(#event_listener_tokens),*];
601        }
602
603        ::axum_wire::inventory::submit! {
604            ::axum_wire::ComponentFactory::new(
605                #wire_name,
606                |snapshot, action, payload, __wire_ctx| {
607                    Box::pin(::axum_wire::with_wire_ctx(__wire_ctx, async move {
608                        let mut component: #self_ty = ::axum_wire::serde_json::from_value(snapshot)
609                            .map_err(|e| ::axum_wire::WireError::Deserialization(e.to_string()))?;
610                        let effects = #call_action_invoke;
611                        let html = if effects.skip_render {
612                            String::new()
613                        } else {
614                            #render_call
615                        };
616                        let new_snapshot = ::axum_wire::serde_json::to_value(&component)
617                            .map_err(|e| ::axum_wire::WireError::Serialization(e.to_string()))?;
618                        Ok(::axum_wire::WireResponse { html, snapshot: new_snapshot, effects })
619                    }))
620                },
621                |__wire_ctx| {
622                    Box::pin(::axum_wire::with_wire_ctx(__wire_ctx.clone(), async move {
623                        let component = #mount_call;
624                        let html = #render_call;
625                        let new_snapshot = ::axum_wire::serde_json::to_value(&component)
626                            .map_err(|e| ::axum_wire::WireError::Serialization(e.to_string()))?;
627                        Ok(::axum_wire::WireResponse { html, snapshot: new_snapshot, effects: ::axum_wire::ActionEffects::default() })
628                    }))
629                },
630                |props: ::axum_wire::serde_json::Value, __wire_ctx: ::axum_wire::WireContext| {
631                    Box::pin(::axum_wire::with_wire_ctx(__wire_ctx.clone(), async move {
632                        let component = #mount_call;
633                        let mut base = ::axum_wire::serde_json::to_value(&component)
634                            .map_err(|e| ::axum_wire::WireError::Serialization(e.to_string()))?;
635                        if let (Some(base_obj), Some(props_obj)) = (base.as_object_mut(), props.as_object()) {
636                            for (k, v) in props_obj {
637                                base_obj.insert(k.clone(), v.clone());
638                            }
639                        }
640                        let component: #self_ty = ::axum_wire::serde_json::from_value(base)
641                            .map_err(|e| ::axum_wire::WireError::Deserialization(e.to_string()))?;
642                        let html = #render_call;
643                        let snapshot = ::axum_wire::serde_json::to_value(&component)
644                            .map_err(|e| ::axum_wire::WireError::Serialization(e.to_string()))?;
645                        Ok(::axum_wire::WireResponse { html, snapshot, effects: ::axum_wire::ActionEffects::default() })
646                    }))
647                },
648                &#self_ty::__WIRE_URL_FIELDS,
649                &#self_ty::__WIRE_EVENT_LISTENERS,
650                &#self_ty::__WIRE_COMPONENT_EVENT_LISTENERS,
651                &#self_ty::__WIRE_LOCKED_FIELDS,
652                #self_ty::__WIRE_LAYOUT,
653            )
654        }
655    };
656
657    TokenStream::from(expanded)
658}
659
660#[proc_macro_attribute]
661pub fn on(attr: TokenStream, item: TokenStream) -> TokenStream {
662    let Ok(parsed) = syn::parse::<syn::Item>(item.clone()) else {
663        return item;
664    };
665
666    match parsed {
667        syn::Item::Struct(mut item_struct) => {
668            let on_attr: proc_macro2::TokenStream = attr.into();
669            item_struct
670                .attrs
671                .push(syn::parse_quote!(#[__wire_on(#on_attr)]));
672            TokenStream::from(quote! { #item_struct })
673        }
674        _ => item,
675    }
676}
677
678// ---------------------------------------------------------------------------
679// html! macro
680// ---------------------------------------------------------------------------
681
682/// JSX-like HTML macro that produces a `String`.
683///
684/// Supports:
685/// - Standard HTML elements: `<div class="foo">...</div>`
686/// - Rust expressions: `<p>{self.count}</p>` or `<p>{some_var}</p>`
687/// - `wire:click`, `wire:submit.prevent`, and other wire directives
688/// - Sub-components via capitalized tags: `<Counter />` mounts a wire component inline
689/// - Void elements: `<br />`, `<input />`
690/// - Fragments: `<>{...}</>`
691///
692/// # Examples
693///
694/// ```ignore
695/// html! {
696///     <div class="container">
697///         <h1>{"Hello"}</h1>
698///         <p>{self.count}</p>
699///         <button wire:click={Self::increment}>{"Click me"}</button>
700///         <Counter />
701///     </div>
702/// }
703/// ```
704#[proc_macro]
705pub fn html(input: TokenStream) -> TokenStream {
706    match rsx::generate(input.into()) {
707        Ok(tokens) => tokens.into(),
708        Err(e) => e.to_compile_error().into(),
709    }
710}