Skip to main content

zerodds_py/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3
4//! Crate `zerodds-py`. Safety classification: **STANDARD** (Binding-FFI).
5//!
6//! PyO3 bindings for the ZeroDDS DCPS API. Provides an importable
7//! Python module `zerodds_py` via `maturin build` or directly via
8//! `cargo build --features extension-module`.
9//!
10//! Spec: OMG DDS 1.4 (formal/2015-04-10) §2.2.2 with Python idioms.
11//!
12//! ## Layer position
13//!
14//! Layer 6 — PSMs / bindings.
15//!
16//! ## Build
17//!
18//! - **Default cargo build** (without Python headers): pyo3 is optional,
19//!   the crate compiles as a lib placeholder. No Python API
20//!   available — this is how the workspace CI runs without a Python dependency.
21//! - **With `--features extension-module`** (or via `maturin build`):
22//!   compiled as a `cdylib` and produces an importable
23//!   Python module `zerodds_py`.
24//!
25//! ## API
26//!
27//! ```python
28//! import zerodds_py as zerodds
29//!
30//! factory = zerodds.DomainParticipantFactory.instance()
31//! participant = factory.create_participant_offline(0)
32//!
33//! topic = participant.create_bytes_topic("Chatter")
34//! publisher = participant.create_publisher()
35//! writer = publisher.create_bytes_writer(topic)
36//!
37//! subscriber = participant.create_subscriber()
38//! reader = subscriber.create_bytes_reader(topic)
39//!
40//! writer.write(b"hello")
41//! samples = reader.take()  # List[bytes]
42//! ```
43//!
44//! Typed `DdsType` bindings (dataclass mapping via the IDL generator)
45//! follow from `crates/idl-rust` through the Python bindings generator.
46
47#![warn(unsafe_code)]
48#![warn(missing_docs)]
49
50#[cfg(feature = "extension-module")]
51mod conditions;
52#[cfg(feature = "extension-module")]
53mod ffi;
54#[cfg(feature = "extension-module")]
55mod listener;
56#[cfg(feature = "extension-module")]
57mod qos;
58
59#[cfg(test)]
60#[allow(clippy::expect_used)]
61mod tests {
62    #[test]
63    fn dcps_re_export_compiles() {
64        // Minimal smoke test: zerodds-dcps is reachable as a dependency.
65        // Die echten PyO3-Tests laufen aus Python heraus (pytest).
66        use zerodds_dcps::DomainParticipantFactory;
67        let _f: &DomainParticipantFactory = DomainParticipantFactory::instance();
68    }
69}