Skip to the content.

API Design Philosophy

Rustuya is engineered with a specific architectural pattern to ensure a balance between high-concurrency device management and deterministic command execution.

1. Asynchronous Device Initialization

Core initialization methods, such as Device::new(), are designed to be non-blocking and return control to the caller immediately.

2. Command Dispatch & nowait Configuration

Methods like set_value(), status(), and sub_discover() provide a configurable execution model via the nowait parameter. This allows the application to balance between strict reliability and high-throughput performance.

nowait = false (Default: Strong Consistency)

Blocks the calling thread until a physical response (acknowledgment or data) is received from the device.

nowait = true (Fire-and-Forget)

Returns control to the caller immediately after the command packet is committed to the local TCP stack.


[!TIP] Error Handling with nowait=true: When using nowait=true, network-level failures (like Offline or ConnectionFailed) are broadcast to the listener(). While the method call itself does not return an error, the application can detect and handle these issues by monitoring the event stream. For critical operations, nowait=false remains the recommended choice for immediate, synchronous error handling.

3. Event-Driven Feedback

Regardless of the nowait setting, Rustuya employs a decoupled event listener mechanism to handle the push-based nature of the Tuya protocol.


4. Choice of Async vs. Sync

Rustuya provides two distinct APIs to suit different application architectures:

[!NOTE] For Python users, the synchronous wrapper provides high-performance interaction without the complexity of asyncio. The Rust core manages all network I/O in dedicated background threads and releases the GIL during blocking calls, allowing Python’s standard threading module to operate with high efficiency.

Thread-Safety & Concurrency

All core types and synchronous wrappers are designed for concurrent use.