kiss3d-macro

Crates.iokiss3d-macro
lib.rskiss3d-macro
version0.36.0
created_at2025-10-18 15:57:17.502047+00
updated_at2025-10-18 15:57:17.502047+00
descriptionProcedural macros for the kiss3d crate
homepage
repository
max_upload_size
id1889324
size6,788
MACs (github:rustcrypto:macs)

documentation

README

kiss3d-macro

Procedural macros for the kiss3d crate.

The #[kiss3d::main] macro

This macro simplifies writing cross-platform kiss3d applications that work on both native platforms and WebAssembly.

Benefits

  • No additional dependencies: You don't need to add pollster or wasm_bindgen_futures to your Cargo.toml - they're automatically available through kiss3d
  • Cleaner code: Eliminates platform-specific boilerplate
  • Less error-prone: No need to manually maintain dual entry points

Problem

When writing kiss3d applications that target both native and WASM, you previously had to write boilerplate code like this:

#[cfg(not(target_arch = "wasm32"))]
fn main() {
    pollster::block_on(run())
}

#[cfg(target_arch = "wasm32")]
fn main() {
    wasm_bindgen_futures::spawn_local(run())
}

async fn run() {
    let mut window = Window::new("My App");
    while window.render_async().await {
        // Your render loop
    }
}

Solution

With the #[kiss3d::main] macro, you can simplify this to:

#[kiss3d::main]
async fn main() {
    let mut window = Window::new("My App");
    while window.render_async().await {
        // Your render loop
    }
}

The macro automatically generates the appropriate platform-specific entry points:

  • On native platforms: uses pollster::block_on to run the async function
  • On WASM: uses wasm_bindgen_futures::spawn_local to spawn the async function

Requirements

  • The function must be named main
  • The function must be async
  • The function cannot have parameters
  • The function should use the async rendering methods (render_async(), render_with_camera_async(), etc.)

Example

See examples/instancing3d.rs and examples/macro_test.rs for complete examples.

Commit count: 0

cargo fmt