Crate webtau_macros

Crate webtau_macros 

Source
Expand description

Proc macros for webtau dual-target command generation.

§v2 #[command] Contract

#[webtau::command]
fn name(state: &T | &mut T [, arg: Type]*) [-> ReturnType] { body }

Supported grammar:

  • First parameter must be a reference: name: &T (read-only) or name: &mut T (mutable). The identifier can be any name (e.g., state, world, game).
  • Additional parameters are named, typed values forwarded as the command’s args.
  • Return type may be:
    • T where T: Serialize — value returned directly.
    • Result<T, E> where T: Serialize, E: Display + Serialize — errors surface to JS.
    • Omitted (unit ()) — command returns nothing.
  • The function name becomes the command name for invoke().

Generated code:

  • Inner function __webtau_<name> containing the original body.
  • #[cfg(not(wasm32))]#[tauri::command] wrapper with State<Mutex<T>>.
  • #[cfg(wasm32)]#[wasm_bindgen] wrapper with args-object deserialize.

Unsupported forms (compile-time error):

  • Methods with self.
  • Missing or non-reference state parameter.
  • Tuple or struct patterns in parameters.
  • Async functions.

Attribute Macros§

command