moddef-rs
Rust runtime + code generator for ModDef (spec v0.4) — declarative Modbus device definitions.
| Crate | What it is |
|---|---|
moddef-core |
Runtime: no_std codec core, Transport trait, typed errors; document parsing (.moddef.yaml / .moddef.json / binary .moddef) and an untyped Device facade under the default std feature. |
moddef-codegen |
Generator: emits a typed struct <Device><T: Transport> per profile, plus the moddef-rs gen CLI. |
moddef-tokio-modbus |
Transport adapter over tokio-modbus (TCP by default, RTU behind the rtu feature). |
Parse a profile at runtime (no codegen)
use ;
use ;
let doc = load?;
let transport = tcp.await?;
let mut dev = new?;
let soc = dev.read_point.await?; // DecodedValue
let hz = dev.read_measurand.await?;
dev.write_point.await?; // §11.4 validated
Or generate a typed client
let mut dev = new;
let state = dev.inverter_status.await?; // InverterRunState (lossless Unknown(u16))
let pv1 = dev.pv1_voltage.await?; // f64, transform applied exactly
let soc = dev.get_state_of_charge.await?; // §26.2 measurand convenience
Generated clients drive the codec core directly over a static descriptor
table — no allocation, no std — so the same client runs on tokio and on a
Cortex-M with embassy. See examples/embedded-nostd
(builds for thumbv7em-none-eabihf).
Feature flags (moddef-core)
| Feature | Adds |
|---|---|
| (none) | Codec core, PointDesc, Transport, errors — no_std, no alloc. |
alloc |
prost schema types, owned DecodedValue, Device facade, binary .moddef parsing. |
std (default) |
YAML/JSON (protojson semantics), fs helpers, import resolution, std::error::Error. |
Development
Conformance tests parse the golden fixtures from ../moddef/fixtures and all
blessed registry profiles from ../devices, and compile-gate generated
clients for every registry profile. DESIGN.md documents the architecture
and the one known wire quirk (prost omits default-valued map-entry fields;
wire-equivalent with Go/TS, not always byte-identical).
License of generated output
Code generated from a ModDef document (for example by moddef gen) is not a
derivative work of the ModDef tooling or runtime. You may license the generated
output under any terms you choose. The runtime it imports (this crate, moddef-core) is
Apache-2.0 licensed; see the LICENSE file for its terms, which apply only to the
runtime, not to your generated code.
License
Apache-2.0. See LICENSE, NOTICE, and CONTRIBUTING.md.