pamoja_zenoh/lib.rs
1#![cfg_attr(not(any(test, feature = "runtime")), no_std)]
2
3//! Zenoh key-expression logic and transport for the pamoja SDK.
4//!
5//! Zenoh addresses data by key expressions: `/`-joined chunks with a small, exact wildcard
6//! language. Before any session is opened, a node has to know whether a key is well-formed, what
7//! its one canonical spelling is, and whether a subscription pattern matches a published key. That
8//! is pure string logic with no I/O, and getting it wrong silently drops or misroutes messages, so
9//! it lives here as checked logic anchored to the Zenoh specification, ahead of the live transport.
10//!
11//! See [`keyexpr`] for the rules and the operations:
12//!
13//! - validity: a key expression is `/`-joined non-empty chunks with no leading, trailing, or
14//! doubled `/`, where `*` and `**` are whole-chunk wildcards and `$*` is a sub-chunk wildcard.
15//! - canonical form: two expressions that select the same keys share one spelling, so equality is
16//! a string comparison; [`canonize`](keyexpr::canonize) produces it.
17//! - matching: [`matches`](keyexpr::matches) tests whether a concrete key is selected by a pattern,
18//! the routing question a subscriber asks of every publication.
19//!
20//! With the `runtime` feature on, `ZenohTransport` adds the live half: it opens a Zenoh session
21//! and implements the core `Transport`, so Zenoh becomes the efficient
22//! edge-to-edge and fleet transport behind the same surface as every other link. Pattern-against-
23//! pattern intersection and inclusion arrive later, cross-checked against Zenoh's own implementation.
24//!
25//! # Examples
26//!
27//! ```
28//! use pamoja_zenoh::keyexpr::{canonize, matches};
29//!
30//! // A subscription with a single-chunk wildcard selects a matching publication.
31//! assert!(matches("room275/*/temperature", "room275/device1/temperature"));
32//! assert!(!matches("room275/*/temperature", "room275/temperature"));
33//!
34//! // `**/*` is valid but not canonical; its one canonical spelling puts the `*` first.
35//! assert_eq!(canonize("robot/sensor/**/*").as_deref(), Some("robot/sensor/*/**"));
36//! ```
37
38extern crate alloc;
39
40pub mod keyexpr;
41
42#[cfg(feature = "runtime")]
43mod transport;
44
45#[cfg(feature = "runtime")]
46pub use transport::{Message, ZenohConfig, ZenohTransport};