| Crates.io | tr181-derive |
| lib.rs | tr181-derive |
| version | 0.1.0 |
| created_at | 2025-10-25 02:30:00.574235+00 |
| updated_at | 2025-10-25 02:30:00.574235+00 |
| description | Procedural macros that generate TR-181 data model access structs and helpers. |
| homepage | |
| repository | https://github.com/Righ-inc/innocontroller |
| max_upload_size | |
| id | 1899575 |
| size | 45,908 |
A Procedural Macro implementation for TR-181 data models access.
This is a Rust procedural macro that automatically generates data struct and access code for TR-181 data models.
Option<String> → TR181Value::StringOption<u8..u64> → TR181Value::UIntOption<i32, i64> → TR181Value::IntOption<bool> → TR181Value::BoolOption<f32, f64> → TR181Value::FloatOption<Vec<u8>> → TR181Value::BytesOption<Enum> → TR181Value::String (read-only)#[tr181(path = "Device.WiFi")] // Object path
#[tr181(param = "SSIDReference")] // Custom parameter name
#[tr181(readonly)] // Read-only parameter
#[tr181(skip)] // Skip field
#[tr181(child)] // Child object
#[tr181(table)] // Table object (combined with child)
use tr181_derive::TR181Node;
#[derive(TR181Node)]
#[tr181(path = "Device.WiFi.AccessPoint.{i}")]
pub struct AccessPoint {
pub enable: Option<bool>,
#[tr181(param = "SSIDReference")]
pub ssid_ref: Option<String>,
#[tr181(readonly)]
pub status: Option<String>,
#[tr181(child)]
pub security: Security,
#[tr181(child, table)]
pub devices: Vec<Device>,
#[tr181(skip)]
pub internal: String,
}
The macro automatically implements the TR181Node trait, including:
get_value() - Get parameter value (with automatic child object navigation)set_value() - Set parameter value (with automatic child object navigation)tr181-derive/src/
├── lib.rs # Main macro implementation
├── attrs.rs # Attribute parsing
└── type_utils.rs # Type detection utilities
Run tests:
cargo test -p tr181-derive
Field names (snake_case) are automatically converted to parameter names (PascalCase):
enable → Enable
ssid_ref → SsidRef
channel_number → ChannelNumber
Override with param attribute:
#[tr181(param = "SSIDReference")]
pub ssid_ref: Option<String>, // → "SSIDReference" instead of "SsidRef"
Generated code recursively handles child objects:
// For Device.Security.KeyPassphrase
// 1. Check if Security child object exists
// 2. Recursively call security.get_value("KeyPassphrase")
Table objects support indexed access:
// Device.Devices.{i}.Name
// 1. Parse index {i}
// 2. Access devices[i]
// 3. Get name parameter
[dependencies]
syn = "2.0" # Rust syntax parsing
quote = "1.0" # Rust code generation
proc-macro2 = "1.0" # Proc macro infrastructure
darling = "0.20" # Attribute parsing
async-trait = "0.1" # Async trait support
BSD-3-Clause