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) orname: &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:
TwhereT: Serialize— value returned directly.Result<T, E>whereT: 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 withState<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.