modem-contract 0.3.0

The management-plane contract of zenoh-modem: the registry, its payload types and their schemas, compiled once for every driver that serves it
Documentation
//! The management-plane contract of zenoh-modem (#119): the registry, its
//! payload types, and the schemas `describe` serves — compiled once, for
//! every driver that serves it.
//!
//! No Zenoh runtime. `zenkey` is linked without its `zenoh` feature, so what
//! is here is the key grammar, the registry slice type and the RFC 08 §7
//! schema envelope: pure data. A driver that links this crate — this
//! repository's, or one for a device the kernel drives — gets the contract
//! and nothing that could open a session; `modem-mgmt` is where the session
//! is.
//!
//! Nothing here knows how a value is produced. `LinkState::of` and its
//! siblings take the facts, not the driver, which is what lets a second
//! driver serve the same documents from a different plane.

use zenkey::{AppName, AppProfile, OriginSalt};

pub mod config;
pub mod documents;

/// The zenkey this contract was compiled against, as `Cargo.lock` pins it —
/// read by `build.rs`, published in `state/modem/sensor` (#122).
pub const ZENKEY_VERSION: &str = env!("ZENKEY_VERSION");
pub mod schema;

/// Typed key builders generated from `registry/` by `zenkey-build`.
///
/// The registry is the management plane's contract, linted at build time and
/// served verbatim by `@rpc/modem/introspect`, so what a consumer reads is
/// literally what the build enforced.
// Generated code is not ours to lint: it is regenerated from the registry
// on every build, so a warning here is not actionable.
#[allow(dead_code, unused_imports, clippy::all)]
pub mod registry {
    include!(concat!(env!("OUT_DIR"), "/zenkey_registry.rs"));
}

/// The application identity every key is minted under.
///
/// A `static` because `AppProfile::local_origin` takes `&'static self` — the
/// origin is cached in a `OnceLock` and handed out by reference, so the profile
/// has to outlive every key built from it.
///
/// The salt is an application constant, compiled in, identical across every
/// deployment. Changing it re-keys every fleet.
///
/// The two arguments are newtypes since zenkey 0.7, which is worth more here
/// than it looks: they are both `&'static str`, they are adjacent, and
/// transposing them would have compiled and silently re-keyed the fleet.
pub static PROFILE: AppProfile = AppProfile::new(
    AppName::new("zenoh-modem"),
    OriginSalt::new("zenoh-modem-host-id-v1"),
);

/// The producer name every driver of this contract publishes under.
///
/// Not the device. The origin is the *host* and the producer is the *component*
/// — the modem itself is a subject chunk, because zenkey RFC 12 §2 decided
/// device-origins never, and because a host may carry more than one device.
pub const PRODUCER: &str = "modem";