Skip to main content

wgame_macros/
lib.rs

1//! Procedural macros for wgame application entry points.
2//!
3//! Provides `#[app]` and `#[window]` macros for creating application and window entry points.
4//!
5//! # Examples
6//!
7//! Application entry point, followed by a single-window entry point:
8//!
9//! ```no_run
10//! #[wgame::app]
11//! async fn main() {
12//!     // Start tasks or create windows here.
13//! }
14//! ```
15//!
16//! ```no_run
17//! #[wgame::window(size = (800, 600))]
18//! async fn main(mut window: wgame::Window<'_>) -> wgame::Result<()> {
19//!     while let Some(_frame) = window.next_frame().await? {}
20//!     Ok(())
21//! }
22//! ```
23
24mod entry_point;
25
26use proc_macro::TokenStream;
27use quote::ToTokens;
28
29/// Marks a function as the main entry point for a wgame application.
30#[proc_macro_attribute]
31pub fn app(attr: TokenStream, item: TokenStream) -> TokenStream {
32    match entry_point::impl_app(attr.into(), item.into()) {
33        Ok(expr) => expr.into_token_stream(),
34        Err(err) => err.into_compile_error(),
35    }
36    .into()
37}
38
39/// Marks a function as the main entry point for a wgame window.
40#[proc_macro_attribute]
41pub fn window(attr: TokenStream, item: TokenStream) -> TokenStream {
42    match entry_point::impl_window(attr.into(), item.into()) {
43        Ok(expr) => expr.into_token_stream(),
44        Err(err) => err.into_compile_error(),
45    }
46    .into()
47}