From 47c7e689386aa8c8a0f323662fc4ec979905bde5 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Tue, 20 Aug 2024 18:14:07 +0200 Subject: [PATCH 1/2] make reliability feature unstable --- zenoh/src/api/session.rs | 7 +++++-- zenoh/src/api/subscriber.rs | 18 +++++++++++++----- zenoh/src/lib.rs | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/zenoh/src/api/session.rs b/zenoh/src/api/session.rs index 7727999158..451c1340ad 100644 --- a/zenoh/src/api/session.rs +++ b/zenoh/src/api/session.rs @@ -39,8 +39,7 @@ use zenoh_protocol::network::{ use zenoh_protocol::{ core::{ key_expr::{keyexpr, OwnedKeyExpr}, - AtomicExprId, CongestionControl, EntityId, ExprId, Parameters, Reliability, WireExpr, - EMPTY_EXPR_ID, + AtomicExprId, CongestionControl, EntityId, ExprId, Parameters, WireExpr, EMPTY_EXPR_ID, }, network::{ self, @@ -102,6 +101,8 @@ use crate::net::{ routing::dispatcher::face::Face, runtime::{Runtime, RuntimeBuilder}, }; +#[cfg(feature = "unstable")] +use crate::pubsub::Reliability; zconfigurable! { pub(crate) static ref API_DATA_RECEPTION_CHANNEL_SIZE: usize = 256; @@ -377,6 +378,7 @@ impl<'s, 'a> SessionDeclarations<'s, 'a> for SessionRef<'a> { SubscriberBuilder { session: self.clone(), key_expr: TryIntoKeyExpr::try_into(key_expr).map_err(Into::into), + #[cfg(feature = "unstable")] reliability: Reliability::DEFAULT, origin: Locality::default(), handler: DefaultHandler::default(), @@ -2035,6 +2037,7 @@ impl<'s> SessionDeclarations<'s, 'static> for Arc { SubscriberBuilder { session: SessionRef::Shared(self.clone()), key_expr: key_expr.try_into().map_err(Into::into), + #[cfg(feature = "unstable")] reliability: Reliability::DEFAULT, origin: Locality::default(), handler: DefaultHandler::default(), diff --git a/zenoh/src/api/subscriber.rs b/zenoh/src/api/subscriber.rs index 2d14cc1adb..0e82a20331 100644 --- a/zenoh/src/api/subscriber.rs +++ b/zenoh/src/api/subscriber.rs @@ -20,7 +20,7 @@ use std::{ }; use zenoh_core::{Resolvable, Wait}; -use zenoh_protocol::{core::Reliability, network::declare::subscriber::ext::SubscriberInfo}; +use zenoh_protocol::network::declare::subscriber::ext::SubscriberInfo; use zenoh_result::ZResult; #[cfg(feature = "unstable")] use {zenoh_config::wrappers::EntityGlobalId, zenoh_protocol::core::EntityGlobalIdProto}; @@ -32,6 +32,8 @@ use super::{ session::{SessionRef, UndeclarableSealed}, Id, }; +#[cfg(feature = "unstable")] +use crate::pubsub::Reliability; pub(crate) struct SubscriberState { pub(crate) id: Id, @@ -200,8 +202,6 @@ pub struct SubscriberBuilder<'a, 'b, Handler> { #[cfg(feature = "unstable")] pub reliability: Reliability, - #[cfg(not(feature = "unstable"))] - pub(crate) reliability: Reliability, #[cfg(feature = "unstable")] pub origin: Locality, @@ -239,16 +239,16 @@ impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler> { let SubscriberBuilder { session, key_expr, + #[cfg(feature = "unstable")] reliability, - origin, handler: _, } = self; SubscriberBuilder { session, key_expr, + #[cfg(feature = "unstable")] reliability, - origin, handler: callback, } @@ -312,6 +312,7 @@ impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler> { let SubscriberBuilder { session, key_expr, + #[cfg(feature = "unstable")] reliability, origin, handler: _, @@ -319,6 +320,7 @@ impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler> { SubscriberBuilder { session, key_expr, + #[cfg(feature = "unstable")] reliability, origin, handler, @@ -329,6 +331,7 @@ impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler> { impl<'a, 'b, Handler> SubscriberBuilder<'a, 'b, Handler> { /// Change the subscription reliability. #[inline] + #[zenoh_macros::unstable] pub fn reliability(mut self, reliability: Reliability) -> Self { self.reliability = reliability; self @@ -336,6 +339,7 @@ impl<'a, 'b, Handler> SubscriberBuilder<'a, 'b, Handler> { /// Change the subscription reliability to `Reliable`. #[inline] + #[zenoh_macros::unstable] pub fn reliable(mut self) -> Self { self.reliability = Reliability::Reliable; self @@ -343,6 +347,7 @@ impl<'a, 'b, Handler> SubscriberBuilder<'a, 'b, Handler> { /// Change the subscription reliability to `BestEffort`. #[inline] + #[zenoh_macros::unstable] pub fn best_effort(mut self) -> Self { self.reliability = Reliability::BestEffort; self @@ -381,9 +386,12 @@ where &key_expr, self.origin, callback, + #[cfg(feature = "unstable")] &SubscriberInfo { reliability: self.reliability, }, + #[cfg(not(feature = "unstable"))] + &SubscriberInfo::default(), ) .map(|sub_state| Subscriber { subscriber: SubscriberInner { diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index 02c90ce0ec..0190acc319 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -230,6 +230,7 @@ pub mod bytes { /// Pub/sub primitives pub mod pubsub { + #[zenoh_macros::unstable] pub use zenoh_protocol::core::Reliability; #[zenoh_macros::unstable] From 9fe3bdd414cdaacad449398fb7e5d57de9c3c100 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Tue, 20 Aug 2024 18:25:03 +0200 Subject: [PATCH 2/2] clippy fix --- zenoh/tests/session.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zenoh/tests/session.rs b/zenoh/tests/session.rs index 916b0c4fb3..7515eefc49 100644 --- a/zenoh/tests/session.rs +++ b/zenoh/tests/session.rs @@ -21,11 +21,14 @@ use std::{ #[cfg(feature = "internal")] use zenoh::internal::runtime::{Runtime, RuntimeBuilder}; +#[cfg(feature = "unstable")] +use zenoh::pubsub::Reliability; use zenoh::{ - config, key_expr::KeyExpr, prelude::*, pubsub::Reliability, qos::CongestionControl, - sample::SampleKind, Session, + config, key_expr::KeyExpr, prelude::*, qos::CongestionControl, sample::SampleKind, Session, }; use zenoh_core::ztimeout; +#[cfg(not(feature = "unstable"))] +use zenoh_protocol::core::Reliability; const TIMEOUT: Duration = Duration::from_secs(60); const SLEEP: Duration = Duration::from_secs(1);