hdc_rs/
lib.rs

1//! # HDC Rust Client Library
2//!
3//! A Rust implementation of the HarmonyOS Device Connector (HDC) client.
4//! This library provides a type-safe, async interface to communicate with HDC servers.
5//!
6//! ## Features
7//!
8//! - **Async/await** - Built on Tokio for efficient async I/O
9//! - **Device Management** - List, connect, and monitor devices
10//! - **Shell Commands** - Execute commands on devices  
11//! - **Port Forwarding** - TCP, Unix sockets, JDWP, Ark debugger support
12//! - **App Management** - Install and uninstall applications (.hap, .hsp)
13//! - **File Transfer** - Send and receive files with options
14//! - **Log Streaming** - Read device logs (hilog)
15//! - **Type-safe API** - Rust's type system ensures correctness
16//! - **Error Handling** - Comprehensive error types with context
17//!
18//! ## Quick Start
19//!
20//! ```no_run
21//! use hdc_rs::HdcClient;
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
25//!     // Connect to HDC server
26//!     let mut client = HdcClient::connect("127.0.0.1:8710").await?;
27//!     
28//!     // List connected devices
29//!     let devices = client.list_targets().await?;
30//!     println!("Devices: {:?}", devices);
31//!     
32//!     if !devices.is_empty() {
33//!         // Select and connect to first device
34//!         client.connect_device(&devices[0]).await?;
35//!         
36//!         // Execute shell command
37//!         let output = client.shell("ls -l /data").await?;
38//!         println!("{}", output);
39//!     }
40//!     
41//!     Ok(())
42//! }
43//! ```
44//!
45//! ## Module Organization
46//!
47//! - [`client`] - Main HDC client implementation
48//! - [`blocking`] - Synchronous/blocking API (requires `blocking` feature)
49//! - [`app`] - Application management types and options
50//! - [`file`] - File transfer types and options
51//! - [`forward`] - Port forwarding types
52//! - [`protocol`] - HDC protocol implementation
53//! - [`error`] - Error types
54//!
55//! ## Blocking API
56//!
57//! For synchronous contexts or FFI bindings (e.g., PyO3), use the blocking module:
58//!
59//! ```no_run
60//! use hdc_rs::blocking::HdcClient;
61//!
62//! let mut client = HdcClient::connect("127.0.0.1:8710")?;
63//! let devices = client.list_targets()?;
64//! println!("Devices: {:?}", devices);
65//! # Ok::<(), Box<dyn std::error::Error>>(())
66//! ```
67//!
68//! ## Examples
69//!
70//! See the `examples/` directory for comprehensive examples:
71//!
72//! - `list_devices` - List connected devices
73//! - `device_monitor` - Monitor device connections
74//! - `simple_shell` - Interactive shell
75//! - `forward_demo` - Port forwarding
76//! - `file_demo` - File transfer
77//! - `app_demo` - App installation
78//! - `hilog_demo` - Device logs
79//! - `comprehensive` - All features
80
81pub mod app;
82#[cfg(feature = "blocking")]
83pub mod blocking;
84pub mod client;
85pub mod error;
86pub mod file;
87pub mod forward;
88pub mod protocol;
89
90pub use app::{InstallOptions, UninstallOptions};
91pub use client::HdcClient;
92pub use error::{HdcError, Result};
93pub use file::{FileTransferDirection, FileTransferOptions};
94pub use forward::{ForwardNode, ForwardTask};