Embedding and no_std

Using the wire model and domain core without the server, building for a microcontroller or WebAssembly, and the Cargo feature matrix.

On this page

The crate is one library sliced with Cargo features. The three lower layers — the wire model, the payload schema and the domain core — are always present, have no I/O and no clock of their own, and compile without std.

The feature matrix#

FeatureAddsPulls in
(none)model, schema, coreserde, serde_json, jiff, rust_decimal, rust_decimal_macros, thiserror
std (default)std implementations, SystemClock—
tls-ring (default)ring fallback for TLS rolesrustls/ring only when rustls is in use
jiffTimestamp to and from jiff::Timestamp, Duration from jiff::SignedDuration — no_std-capable—
clientthe HTTP clientreqwest, rustls, tokio, url
venthe VEN runtime loop, on top of clientasync-trait
conformancethe black-box suite, on top of client—
vtnthe serveraxum, tower, tower-http, tokio, uuid, sha2, base64
sqliteSQLite storagesqlx, ring
postgresPostgreSQL storagesqlx, ring
internal-auththe VTN's own /auth/tokenjsonwebtoken, argon2, rand
external-authJWT validation against a JWKSjsonwebtoken, reqwest, rustls
webhookwebhook deliveryreqwest, rustls, rand, hmac, sha2
webhook-signatureverifying a delivery's signature — no_std-capable, builds for thumbv7em-none-eabihfhmac, sha2
mqttstandalone MQTT client, OpenADR publisher with vtn, subscriber with ventokio, rustls, tokio-rustls, webpki-roots
mdnsadvertising a local VTN (with vtn) and browsing for one (with ven)mdns-sd
tlsthe VTN's own TLS listener, and an optional client-certificate gaterustls, tokio-rustls, hyper, hyper-util

Every one of those flags is read by a cfg somewhere. A feature flag nothing reads is a claim the manifest makes and nothing keeps, and CI builds each feature separately as well as the all-features configuration.

Three combinations are worth naming. ven is the whole VEN side and pulls in no server; vtn,client is what the command-line binary wants, because openadr get talks to a VTN with the same client library anybody else would use; and conformance deliberately depends on client and on nothing in vtn, because a suite that could reach into the server it measures would be measuring that server's opinion of itself.

Using the model alone#

Parsing, validating and rendering OpenADR JSON needs no server and no client:

$ cargo add openadr --no-default-features --features std

That build depends on the six crates in the first row and their own dependencies, and tests/footprint.rs fails if anything else becomes reachable. It needs Rust 1.88.

use openadr::model::{Event, EventRequest};

let event: Event = serde_json::from_slice(&body)?;
let json = serde_json::to_vec(&event)?;

What you get beyond serde derives:

Newtypes that cannot hold an illegal value. ObjectId enforces the schema's ^[a-zA-Z0-9_-]{1,128}$ and additionally refuses null, undefined, . and .., which would be ambiguous in a path or in JSON. Same for ClientId, Target, VenName, ResourceName, ClientName, ProgramName, PayloadType, Unit. Nothing downstream asks whether a name is well formed.

Sentinels as variants. StartTime::{Now, At} and Duration::{Forever, Finite}.

Requests and responses as distinct types. ProgramRequest has no id field, so a POST body cannot name one.

Decimal values. Value::Number holds a Decimal (openadr::model::Decimal, no rust_decimal dependency needed), serialised as a JSON number. A fractional value is written only if binary64 carries it exactly, and refused otherwise (numeric precision). Value equality is semantic, not representational: Integer(60) equals Number(60), because JSON has one number type and which variant a parse produces depends only on how the peer wrote it.

A duration parser that follows the schema, not ISO 8601. The specification's pattern forbids fractional hours and minutes and mutually excludes days and weeks; ISO 8601 does not. PT1.5H is refused here and accepted by a general-purpose parser.

Time from your own library. With jiff, jiff::Timestamp::from(window.start) and back, with no error to handle; the feature ties you to jiff 1. Otherwise, as_nanosecond and from_nanosecond.

Durations that read like the User Guide. Duration::from_secs(3600) writes PT1H and from_nanos writes PT1H30M0.5S. TryFrom takes a core::time::Duration, and with jiff a jiff::SignedDuration.

Duration equality is fieldwise: PT60M and PT1H are different values, because they render differently and a round trip must be lossless. Compare lengths with as_secs or as_nanos.

no_std#

$ cargo add openadr --no-default-features

Verified in CI for thumbv7em-none-eabihf (Cortex-M4F) and wasm32-unknown-unknown. The specification's own security chapter has the appliance-class VEN in mind.

no_std here means no operating system, not no heap. The wire model is Strings and Vecs — there is no version of OpenADR that works without an allocator — so the crate always does extern crate alloc. There is no alloc feature, because it would have had one state and one build failure.

What that build gives you: parse and render every object, expand an event's intervals into absolute windows, resolve concurrent events into a timeline, compute report schedules, and evaluate the payload enumerations. What it does not: any HTTP, and SystemClock — supply the time yourself.

use openadr::core::{Clock, IntervalExpander};
use openadr::model::Timestamp;

#[derive(Debug)]
struct RtcClock;

impl Clock for RtcClock {
    fn now(&self) -> Timestamp {
        Timestamp::from_second(rtc_seconds()).unwrap()
    }
}

let timeline = Timeline::build(events, &IntervalExpander::new(&RtcClock), from, to);

Bare-metal builds are also a guard rather than only a product feature: they are the cheapest way to notice that somebody reached for std::time::SystemTime in the domain core.

Embedding the VTN#

Vtn::router() returns an ordinary axum::Router, so the server mounts inside a larger service:

let vtn = Vtn::builder()
    .storage(PostgresStorage::shared(&url).await?)
    .authenticator(Arc::new(auth))
    .build();

let app = axum::Router::new()
    .nest("/openadr", vtn.router())
    .merge(my_own_routes());

// `Vtn::serve` spawns this. If you run the router yourself, you must too —
// otherwise nothing is ever delivered.
vtn.dispatcher().clone().spawn();

Calling a Storage method directly rather than through the API means supplying a Fanout — the snapshot of who should be told:

storage.create_program(request, now, &Fanout::none()).await?;

Fanout::none() is the whole ceremony for an embedder that does not want notifications. Every mutating method takes one because the notification has to be queued in the same transaction as the change, and a backend cannot work out the recipients from inside its own write.

Deterministic tests#

Time and randomness are injected, so a schedule can be replayed exactly:

let notifier = RecordingNotifier::shared();
let vtn = Vtn::builder()
    .storage(MemoryStorage::shared())
    .clock(Arc::new(FixedClock::new("2026-02-11T06:00:00Z".parse()?)))
    .notifier(notifier.clone())
    .build();

// Drain the outbox instead of sleeping: `drain` runs until nothing is due, so
// retry counts are exact rather than timing-dependent.
vtn.dispatcher().drain().await;
assert_eq!(notifier.delivered().len(), 1);

Versioning#

Pre-1.0. Breaking changes are possible on any release, the SQL schema is authoritative rather than historical, and there are no migrations — a schema change is a reason to recreate the database.

The crate tracks OpenADR 3.1.0, accepting the resource request bodies of both 3.1.0 and the 3.1.1 development copy. There is no 3.0 compatibility: 3.1 is not backwards compatible, and carrying both would mean two shapes for targets, two locations for /resources, and flat programme fields alongside attributes — permanently, in the middle of the model. Profile deviations are handled by adapters at the edge (model::adapt).