1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT extern crate proc_macro; use crate::context::ContextItems; use proc_macro::TokenStream; use syn::parse_macro_input; mod command; #[macro_use] mod context; /// Mark a function as a command handler. It creates a wrapper function with the necessary glue code. /// /// # Stability /// The output of this macro is managed internally by Tauri, /// and should not be accessed directly on normal applications. /// It may have breaking changes in the future. #[proc_macro_attribute] pub fn command(attributes: TokenStream, item: TokenStream) -> TokenStream { command::wrapper(attributes, item) } /// Accepts a list of commands functions. Creates a handler that allows commands to be called from JS with invoke(). /// /// # Example /// ```rust,ignore /// use tauri::command; /// #[command] /// fn command_one() {} /// #[command] /// fn command_two() {} /// fn main() { /// tauri::Builder::default() /// .invoke_handler(tauri::generate_handler![command_one, command_two]) /// .run(tauri::generate_context!()) /// .expect("error while running tauri application"); /// } /// ``` /// # Stability /// The output of this macro is managed internally by Tauri, /// and should not be accessed directly on normal applications. /// It may have breaking changes in the future. #[proc_macro] pub fn generate_handler(item: TokenStream) -> TokenStream { parse_macro_input!(item as command::Handler).into() } /// Reads a Tauri config file and generates a `::tauri::Context` based on the content. /// /// # Stability /// The output of this macro is managed internally by Tauri, /// and should not be accessed directly on normal applications. /// It may have breaking changes in the future. #[proc_macro] pub fn generate_context(items: TokenStream) -> TokenStream { // this macro is exported from the context module let path = parse_macro_input!(items as ContextItems); context::generate_context(path).into() }