Skip to content

Commit 11c2978

Browse files
authored
fix RecoveryConfig (#1973)
* fix RecoveryConfig RecoveryConfig used a generic parameter that was not even exposed, instead of a simple boolean parameter * fix lint * implement default only for unconfigured * typo * put back default for configured
1 parent 34fc747 commit 11c2978

File tree

2 files changed

+15
-39
lines changed

2 files changed

+15
-39
lines changed

zenoh-ext/src/advanced_subscriber.rs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Contributors:
1212
// ZettaScale Zenoh Team, <[email protected]>
1313
//
14-
use std::{collections::BTreeMap, future::IntoFuture, marker::PhantomData, str::FromStr};
14+
use std::{collections::BTreeMap, future::IntoFuture, str::FromStr};
1515

1616
use zenoh::{
1717
config::ZenohId,
@@ -88,31 +88,16 @@ impl HistoryConfig {
8888
}
8989
}
9090

91-
#[derive(Default, Clone, Copy)]
92-
pub struct Unconfigured;
93-
#[derive(Default, Clone, Copy)]
94-
pub struct Configured;
95-
96-
#[derive(Default, Clone, Copy)]
91+
#[derive(Debug, Default, Clone, Copy)]
9792
/// Configure retransmission.
9893
#[zenoh_macros::unstable]
99-
pub struct RecoveryConfig<T> {
94+
pub struct RecoveryConfig<const CONFIGURED: bool = true> {
10095
periodic_queries: Option<Duration>,
101-
heartbeat: Option<()>,
102-
phantom: PhantomData<T>,
103-
}
104-
105-
impl<T> std::fmt::Debug for RecoveryConfig<T> {
106-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107-
let mut s = f.debug_struct("RetransmissionConf");
108-
s.field("periodic_queries", &self.periodic_queries);
109-
s.field("heartbeat", &self.heartbeat);
110-
s.finish()
111-
}
96+
heartbeat: bool,
11297
}
11398

11499
#[zenoh_macros::unstable]
115-
impl RecoveryConfig<Unconfigured> {
100+
impl RecoveryConfig<false> {
116101
/// Enable periodic queries for not yet received Samples and specify their period.
117102
///
118103
/// This allows to retrieve the last Sample(s) if the last Sample(s) is/are lost.
@@ -123,11 +108,10 @@ impl RecoveryConfig<Unconfigured> {
123108
/// [`sample_miss_detection`](crate::AdvancedPublisherBuilder::sample_miss_detection).
124109
#[zenoh_macros::unstable]
125110
#[inline]
126-
pub fn periodic_queries(self, period: Duration) -> RecoveryConfig<Configured> {
111+
pub fn periodic_queries(self, period: Duration) -> RecoveryConfig<true> {
127112
RecoveryConfig {
128113
periodic_queries: Some(period),
129-
heartbeat: None,
130-
phantom: PhantomData::<Configured>,
114+
heartbeat: false,
131115
}
132116
}
133117

@@ -141,11 +125,10 @@ impl RecoveryConfig<Unconfigured> {
141125
/// [`sporadic_heartbeat`](crate::advanced_publisher::MissDetectionConfig::sporadic_heartbeat).
142126
#[zenoh_macros::unstable]
143127
#[inline]
144-
pub fn heartbeat(self) -> RecoveryConfig<Configured> {
128+
pub fn heartbeat(self) -> RecoveryConfig<true> {
145129
RecoveryConfig {
146130
periodic_queries: None,
147-
heartbeat: Some(()),
148-
phantom: PhantomData::<Configured>,
131+
heartbeat: true,
149132
}
150133
}
151134
}
@@ -156,7 +139,7 @@ pub struct AdvancedSubscriberBuilder<'a, 'b, 'c, Handler, const BACKGROUND: bool
156139
pub(crate) session: &'a Session,
157140
pub(crate) key_expr: ZResult<KeyExpr<'b>>,
158141
pub(crate) origin: Locality,
159-
pub(crate) retransmission: Option<RecoveryConfig<Configured>>,
142+
pub(crate) retransmission: Option<RecoveryConfig>,
160143
pub(crate) query_target: QueryTarget,
161144
pub(crate) query_timeout: Duration,
162145
pub(crate) history: Option<HistoryConfig>,
@@ -275,7 +258,7 @@ impl<'a, 'c, Handler, const BACKGROUND: bool>
275258
/// [`sample_miss_detection`](crate::AdvancedPublisherBuilder::sample_miss_detection).
276259
#[zenoh_macros::unstable]
277260
#[inline]
278-
pub fn recovery(mut self, conf: RecoveryConfig<Configured>) -> Self {
261+
pub fn recovery(mut self, conf: RecoveryConfig) -> Self {
279262
self.retransmission = Some(conf);
280263
self
281264
}
@@ -1062,7 +1045,7 @@ impl<Handler> AdvancedSubscriber<Handler> {
10621045
None
10631046
};
10641047

1065-
let heartbeat_subscriber = if retransmission.is_some_and(|r| r.heartbeat.is_some()) {
1048+
let heartbeat_subscriber = if retransmission.is_some_and(|r| r.heartbeat) {
10661049
let ke_heartbeat_sub = &key_expr / KE_ADV_PREFIX / KE_PUB / KE_STARSTAR;
10671050
let statesref = statesref.clone();
10681051
tracing::debug!(

zenoh-ext/src/subscriber_ext.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use zenoh::{
2525

2626
#[allow(deprecated)]
2727
use crate::{
28-
advanced_subscriber::{Configured, HistoryConfig},
29-
querying_subscriber::QueryingSubscriberBuilder,
28+
advanced_subscriber::HistoryConfig, querying_subscriber::QueryingSubscriberBuilder,
3029
AdvancedSubscriberBuilder, ExtractSample, FetchingSubscriberBuilder, RecoveryConfig,
3130
};
3231

@@ -148,10 +147,7 @@ pub trait AdvancedSubscriberBuilderExt<'a, 'b, 'c, Handler> {
148147
/// that enable [`cache`](crate::AdvancedPublisherBuilder::cache) and
149148
/// [`sample_miss_detection`](crate::AdvancedPublisherBuilder::sample_miss_detection).
150149
#[zenoh_macros::unstable]
151-
fn recovery(
152-
self,
153-
conf: RecoveryConfig<Configured>,
154-
) -> AdvancedSubscriberBuilder<'a, 'b, 'c, Handler>;
150+
fn recovery(self, conf: RecoveryConfig) -> AdvancedSubscriberBuilder<'a, 'b, 'c, Handler>;
155151

156152
/// Allow this subscriber to be detected through liveliness.
157153
#[zenoh_macros::unstable]
@@ -288,10 +284,7 @@ impl<'a, 'b, 'c, Handler> AdvancedSubscriberBuilderExt<'a, 'b, 'c, Handler>
288284
/// that enable [`cache`](crate::AdvancedPublisherBuilder::cache) and
289285
/// [`sample_miss_detection`](crate::AdvancedPublisherBuilder::sample_miss_detection).
290286
#[zenoh_macros::unstable]
291-
fn recovery(
292-
self,
293-
conf: RecoveryConfig<Configured>,
294-
) -> AdvancedSubscriberBuilder<'a, 'b, 'c, Handler> {
287+
fn recovery(self, conf: RecoveryConfig) -> AdvancedSubscriberBuilder<'a, 'b, 'c, Handler> {
295288
AdvancedSubscriberBuilder::new(self).recovery(conf)
296289
}
297290

0 commit comments

Comments
 (0)