Expand description
§HDC Rust Client Library
A Rust implementation of the HarmonyOS Device Connector (HDC) client. This library provides a type-safe, async interface to communicate with HDC servers.
§Features
- Async/await - Built on Tokio for efficient async I/O
- Device Management - List, connect, and monitor devices
- Shell Commands - Execute commands on devices
- Port Forwarding - TCP, Unix sockets, JDWP, Ark debugger support
- App Management - Install and uninstall applications (.hap, .hsp)
- File Transfer - Send and receive files with options
- Log Streaming - Read device logs (hilog)
- Type-safe API - Rust’s type system ensures correctness
- Error Handling - Comprehensive error types with context
§Quick Start
use hdc_rs::HdcClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to HDC server
let mut client = HdcClient::connect("127.0.0.1:8710").await?;
// List connected devices
let devices = client.list_targets().await?;
println!("Devices: {:?}", devices);
if !devices.is_empty() {
// Select and connect to first device
client.connect_device(&devices[0]).await?;
// Execute shell command
let output = client.shell("ls -l /data").await?;
println!("{}", output);
}
Ok(())
}§Module Organization
client- Main HDC client implementationblocking- Synchronous/blocking API (requiresblockingfeature)app- Application management types and options- [
file] - File transfer types and options forward- Port forwarding typesprotocol- HDC protocol implementationerror- Error types
§Blocking API
For synchronous contexts or FFI bindings (e.g., PyO3), use the blocking module:
use hdc_rs::blocking::HdcClient;
let mut client = HdcClient::connect("127.0.0.1:8710")?;
let devices = client.list_targets()?;
println!("Devices: {:?}", devices);§Examples
See the examples/ directory for comprehensive examples:
list_devices- List connected devicesdevice_monitor- Monitor device connectionssimple_shell- Interactive shellforward_demo- Port forwardingfile_demo- File transferapp_demo- App installationhilog_demo- Device logscomprehensive- All features
Re-exports§
pub use app::InstallOptions;pub use app::UninstallOptions;pub use client::HdcClient;pub use error::HdcError;pub use error::Result;pub use file::FileTransferDirection;pub use file::FileTransferOptions;pub use forward::ForwardNode;pub use forward::ForwardTask;