Skip to main content

vtui_macros/
lib.rs

1use proc_macro::TokenStream;
2
3use crate::component::ComponentFn;
4
5mod component;
6
7/// Marks a function as a UI component.
8///
9/// # Features
10///
11/// - Validates the function signature and returns helpful errors.
12/// - Injects a default second argument when one is not provided.
13///
14/// # Example
15///
16/// ```rust
17/// #[component]
18/// fn HelloWorld(c: Component) -> Node {
19///     c.compose(|_| {})
20/// }
21/// ```
22#[proc_macro_attribute]
23pub fn component(_: TokenStream, item: TokenStream) -> TokenStream {
24    match syn::parse::<ComponentFn>(item) {
25        Ok(input) => input.expand().into(),
26        Err(err) => err.into_compile_error().into(),
27    }
28}