From 5e14e66c66ebd87455de8be8dcb94fe74ca17f0d Mon Sep 17 00:00:00 2001 From: carter Date: Sat, 19 Sep 2026 13:09:53 -0600 Subject: [PATCH] Make users not need to specify a zenoh dependency --- CHANGELOG.md | 5 +++++ Cargo.lock | 1 - README.md | 6 +++++- roslibrust/Cargo.toml | 2 -- roslibrust_zenoh/src/lib.rs | 8 ++++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0308138f..6385499f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- `roslibrust::zenoh` now re-exports `open`, `Config`, and `Session`, allowing users to construct a + `ZenohClient` without depending directly on the `zenoh` crate. + ## 0.25.0 - September 19th, 2026 ### Added diff --git a/Cargo.lock b/Cargo.lock index 3613645a..f8f481f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3489,7 +3489,6 @@ dependencies = [ "test-log", "tokio", "tokio-stream", - "zenoh", ] [[package]] diff --git a/README.md b/README.md index 6a12acb8..aaacc1e2 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,11 @@ async fn main() -> Result<(), Box> { // Relay messages over a zenoh connection compatible with zenoh-ros1-plugin / zenoh-ros1-bridge #[cfg(feature = "zenoh")] { - let ros = roslibrust::zenoh::ZenohClient::new(zenoh::open(zenoh::Config::default()).await.unwrap()); + let ros = roslibrust::zenoh::ZenohClient::new( + roslibrust::zenoh::open(roslibrust::zenoh::Config::default()) + .await + .unwrap(), + ); relay(ros).await?; } diff --git a/roslibrust/Cargo.toml b/roslibrust/Cargo.toml index 34e4edf0..bad63f10 100644 --- a/roslibrust/Cargo.toml +++ b/roslibrust/Cargo.toml @@ -34,8 +34,6 @@ roslibrust_codegen = { path = "../roslibrust_codegen" } roslibrust_codegen_macro = { path = "../roslibrust_codegen_macro" } # Slightly weird, but used in documentation examples roslibrust_test = { path = "../roslibrust_test" } -# Slightly weird, but used in documentation examples -zenoh = "1.7" # Provides test timeout ntest = "0.9" diff --git a/roslibrust_zenoh/src/lib.rs b/roslibrust_zenoh/src/lib.rs index 8a94fa45..73826aeb 100644 --- a/roslibrust_zenoh/src/lib.rs +++ b/roslibrust_zenoh/src/lib.rs @@ -16,6 +16,10 @@ use std::{ use tokio::sync::RwLock; use zenoh::bytes::ZBytes; +// Re-export the parts of Zenoh's session API needed to construct a `ZenohClient`, so users of +// `roslibrust::zenoh` do not also need a direct dependency on the `zenoh` crate. +pub use zenoh::{open, Config, Session}; + /// Serialize a runtime-selected message as the ROS1 message body carried by the Zenoh ROS1 /// bridge. pub fn serialize_dynamic_message(message: &DynamicMessage) -> DynamicMessageResult> { @@ -49,13 +53,13 @@ const DISCOVERY_LOST_AFTER: Duration = Duration::from_secs(3); #[derive(Clone)] pub struct ZenohClient { _discovery_monitor: Arc, - session: zenoh::Session, + session: Session, graph: Arc>>, } impl ZenohClient { /// Creates a new client wrapped around a Zenoh session - pub fn new(session: zenoh::Session) -> Self { + pub fn new(session: Session) -> Self { let graph = Arc::new(RwLock::new(BTreeMap::new())); let discovery_monitor = Arc::new(spawn_discovery_monitor(session.clone(), graph.clone())); Self {