lib.rs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2006-2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author notes
  8. * 2025-10-29 foxglove Modular macro library for RT-Thread Rust
  9. */
  10. /*! RT-Thread Rust Macro Library
  11. This library provides Rust macros for RT-Thread system, including:
  12. - `rt_thread_main!` - Main thread entry macro
  13. - `rt_component_export!` - Component export macro
  14. - `rt_app_export!` - Application export macro
  15. - `msh_cmd_export!` - Shell command export macro
  16. ## Usage Examples
  17. ### Main Thread Entry
  18. ```rust
  19. use rt_macros::rt_thread_main;
  20. #[rt_thread_main]
  21. fn main() {
  22. println!("Hello RT-Thread!");
  23. }
  24. ```
  25. ### Component Export
  26. ```rust
  27. use rt_macros::rt_component_export;
  28. #[rt_component_export]
  29. fn my_component_init() {
  30. // Component initialization code
  31. }
  32. ```
  33. ### Application Export
  34. ```rust
  35. use rt_macros::rt_app_export;
  36. #[rt_app_export]
  37. fn my_app_init() {
  38. // Application initialization code
  39. }
  40. ```
  41. ### Shell Command Export
  42. ```rust
  43. use rt_macros::msh_cmd_export;
  44. #[msh_cmd_export(name = "hello", desc = "Say hello")]
  45. fn hello_cmd(args: vec::IntoIter<rt_rust::param::ParamItem>) {
  46. println!("Hello from shell command!");
  47. }
  48. ```
  49. */
  50. #[macro_use]
  51. extern crate quote;
  52. use proc_macro::TokenStream;
  53. /* Import modular macro definitions */
  54. mod macros;
  55. /* Modular macro definitions */
  56. /* RT-Thread main thread entry macro */
  57. #[proc_macro_attribute]
  58. pub fn rt_thread_main(args: TokenStream, input: TokenStream) -> TokenStream {
  59. macros::main::rt_thread_main(args, input)
  60. }
  61. /* RT-Thread component export macro */
  62. #[proc_macro_attribute]
  63. pub fn rt_component_export(args: TokenStream, input: TokenStream) -> TokenStream {
  64. macros::component::rt_component_export(args, input)
  65. }
  66. /* RT-Thread application export macro */
  67. #[proc_macro_attribute]
  68. pub fn rt_app_export(args: TokenStream, input: TokenStream) -> TokenStream {
  69. macros::app::rt_app_export(args, input)
  70. }
  71. /* MSH command export macro */
  72. #[proc_macro_attribute]
  73. pub fn msh_cmd_export(args: TokenStream, input: TokenStream) -> TokenStream {
  74. macros::cmd::msh_cmd_export(args, input)
  75. }