walnux/Documentation/applications/examples/rust/hello/index.rst
Huang Qi 69495f8a40 docs: Add Rust examples including JSON handling and Slint UI framework
Summary:
- Added two new Rust example applications to the documentation:
  - `hello` example showcasing JSON serialization/deserialization, async runtime usage, and C interoperability in a NuttX environment
  - `slint` example demonstrating the integration of the Slint UI framework with NuttX's framebuffer and touchscreen devices for creating GUI applications in Rust
- Each example includes detailed explanations of key features and how they are implemented using Rust's modern language capabilities

Impact:
- Enhances the documentation for Rust development within NuttX, providing clear and practical examples for developers
- Facilitates easier adoption of Rust for new projects by demonstrating how to leverage its features while maintaining compatibility with existing NuttX infrastructure
- No changes to the core NuttX system; the additions are entirely within the documentation and examples directory

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-01-30 13:45:01 +08:00

30 lines
1.2 KiB
ReStructuredText

==================================
`hello` Example in Rust
==================================
This example demonstrates how to use Rust's powerful features in a NuttX environment, including:
- **JSON Serialization/Deserialization**: Using the popular `serde` and `serde_json` crates to work with JSON data
- **Async Runtime**: Demonstrates basic usage of the `tokio` async runtime
- **C Interoperability**: Shows how to expose Rust functions to be called from C code
Key Features
------------
1. JSON Handling
- Defines a `Person` struct with `Serialize` and `Deserialize` traits
- Serializes Rust structs to JSON strings
- Deserializes JSON strings into Rust structs
- Demonstrates pretty-printing JSON
2. Async Runtime
- Initializes a single-threaded `tokio` runtime
- Runs a simple async task that prints a message
3. C Interop
- Exports `hello_rust_cargo_main` function with `#[no_mangle]` for C calling
- Uses `extern "C"` to define the C ABI
The example shows how Rust's modern features can be used in embedded systems while maintaining compatibility with C-based systems.
This example serves as a foundation for building more complex Rust applications in NuttX that need to handle JSON data and async operations.