diff options
| author | zhang san <[email protected]> | 2025-12-08 18:34:25 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-08 18:34:25 +0800 |
| commit | 69980f8b9d29b38dbd4ddf6373b4b45f3a138409 (patch) | |
| tree | 21dd9a8ce80e3d30192e9ffa56ea39a199bae309 /components/rust/examples/application/loadlib/src | |
| parent | cd1d47b87c5d47e131730e5506eb3ad77d357653 (diff) | |
Adding Rust Language Support for RT-Thread #10910
Diffstat (limited to 'components/rust/examples/application/loadlib/src')
| -rw-r--r-- | components/rust/examples/application/loadlib/src/lib.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/components/rust/examples/application/loadlib/src/lib.rs b/components/rust/examples/application/loadlib/src/lib.rs new file mode 100644 index 0000000000..d60175f5fa --- /dev/null +++ b/components/rust/examples/application/loadlib/src/lib.rs @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2006-2025, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author notes + * 2025-10-10 foxglove load library example + * 2025-10-29 foxglove Updated to demonstrate new modular macro interface + */ +#![no_std] + +extern crate alloc; + +use rt_macros::msh_cmd_export; +use rt_rust::println; +use rt_rust::get_libfn; +use core::ffi::{c_int, c_char}; +use rt_rust::param::Param; + +#[msh_cmd_export(name = "rust_dl_demo", desc = "Rust dynamic library demo")] +fn main(_param: Param) { + println!("\n=== Dynamic Library Demo ==="); + + get_libfn!("/hello.mo", "main", my_hello, ()); + my_hello(); + + get_libfn!("/libmylib.mo", "rust_mylib_add", my_add, c_int, a: c_int, b: c_int); + let s = my_add(15, 20); + println!("my_add(15, 20) = {}", s); + + get_libfn!("/libmylib.mo", "rust_mylib_println", my_println, (), s: *const c_char); + my_println(b"rustlib: Hello World\0".as_ptr() as *const c_char); +} |
