summaryrefslogtreecommitdiff
path: root/components/rust/examples/component/component_registry/src
diff options
context:
space:
mode:
authorzhang san <[email protected]>2025-12-08 18:34:25 +0800
committerGitHub <[email protected]>2025-12-08 18:34:25 +0800
commit69980f8b9d29b38dbd4ddf6373b4b45f3a138409 (patch)
tree21dd9a8ce80e3d30192e9ffa56ea39a199bae309 /components/rust/examples/component/component_registry/src
parentcd1d47b87c5d47e131730e5506eb3ad77d357653 (diff)
Adding Rust Language Support for RT-Thread #10910
Diffstat (limited to 'components/rust/examples/component/component_registry/src')
-rw-r--r--components/rust/examples/component/component_registry/src/lib.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/components/rust/examples/component/component_registry/src/lib.rs b/components/rust/examples/component/component_registry/src/lib.rs
new file mode 100644
index 0000000000..beff2df698
--- /dev/null
+++ b/components/rust/examples/component/component_registry/src/lib.rs
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2006-2025, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author notes
+ * 2025-10-25 foxglove Component registry for unified component registration
+ * 2025-10-29 foxglove Updated to demonstrate new modular macro interface
+ */
+#![no_std]
+
+extern crate alloc;
+
+/* Demonstrate the new modular macro interface */
+use rt_macros::rt_component_export;
+use rt_rust::param::{Param, ParamItem};
+use rt_rust::println;
+
+/* Re-export component functionality for other modules */
+#[cfg(feature = "enable-log")]
+pub use em_component_log::*;
+#[cfg(feature = "enable-log")]
+use em_component_log::logging::Level;
+
+/** Unified component registration entrypoint */
+#[cfg(feature = "enable-log")]
+#[rt_component_export(name = "rust_component_registry")]
+fn init_registry_component() {
+ println!("[logging component init] hello world");
+ log!(Level::Info, "hello world");
+ info!("hello world");
+ warn!("hello world");
+ error!("hello world");
+ trace!("hello world");
+ debug!("hello world");
+}
+
+/** Provide a no-op implementation when no component feature is enabled */
+#[cfg(not(feature = "enable-log"))]
+pub extern "C" fn component_init() {
+ /* Empty implementation to ensure the library still links */
+}