Skip to the content.

Rust API Reference

This document provides a detailed reference for the core components of Rustuya: Device, SubDevice, and Scanner. All core types are thread-safe and designed for high-concurrency environments.

Importing the Library

Depending on the application architecture, select the appropriate import path:

Choosing sync vs async

Both facades wrap the same internal actor and reach the same backing Tokio runtime — the sync types are just blocking bridges. Pick by the context you call from:

When you’re calling from… Use
A non-async program (CLI, sync binary, scripting helpers) rustuya::sync::{Device, SubDevice, Scanner}
Inside a tokio runtime (#[tokio::main], tokio::spawn, axum, etc.) rustuya::{Device, DeviceBuilder, Scanner} (async)

Calling the sync API from inside a Tokio runtime is not supported: the wrappers use blocking_send, which would otherwise panic. Since v0.3.0 a runtime guard turns that into a clear error, but choose the right facade up front rather than relying on the guard.


1. System Optimization

maximize_fd_limit()


2. Device API

Direct interaction with individual Tuya devices.

Device::new()

Device::builder()

device.status()

device.set_value()

device.set_dps()

device.listener()

unified_listener()


3. SubDevice API

Interaction with sub-devices (endpoints) through a parent Gateway Device. Obtained via device.sub(cid).

device.sub()

sub_device.status() / set_value() / set_dps()


4. Scanner API

UDP-based device discovery on the local network.

Scanner::scan()

Scanner::scan_stream()

Advanced configuration (multi-homed hosts)

Every knob below takes &self and mutates the shared global scanner state; they exist on both the async Scanner and rustuya::sync::Scanner.