lib.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. extern crate proc_macro;
  5. use crate::context::ContextItems;
  6. use proc_macro::TokenStream;
  7. use syn::parse_macro_input;
  8. mod command;
  9. #[macro_use]
  10. mod context;
  11. /// Mark a function as a command handler. It creates a wrapper function with the necessary glue code.
  12. ///
  13. /// # Stability
  14. /// The output of this macro is managed internally by Tauri,
  15. /// and should not be accessed directly on normal applications.
  16. /// It may have breaking changes in the future.
  17. #[proc_macro_attribute]
  18. pub fn command(attributes: TokenStream, item: TokenStream) -> TokenStream {
  19. command::wrapper(attributes, item)
  20. }
  21. #[proc_macro]
  22. pub fn generate_handler(item: TokenStream) -> TokenStream {
  23. parse_macro_input!(item as command::Handler).into()
  24. }
  25. /// Reads a Tauri config file and generates a `::tauri::Context` based on the content.
  26. ///
  27. /// # Stability
  28. /// The output of this macro is managed internally by Tauri,
  29. /// and should not be accessed directly on normal applications.
  30. /// It may have breaking changes in the future.
  31. #[proc_macro]
  32. pub fn generate_context(items: TokenStream) -> TokenStream {
  33. // this macro is exported from the context module
  34. let path = parse_macro_input!(items as ContextItems);
  35. context::generate_context(path).into()
  36. }