zenoh_ext/publisher_ext.rs
1//
2// Copyright (c) 2023 ZettaScale Technology
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8//
9// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10//
11// Contributors:
12// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
13//
14use zenoh::pubsub::PublisherBuilder;
15
16use crate::{advanced_cache::CacheConfig, AdvancedPublisherBuilder, MissDetectionConfig};
17
18/// Some extensions to the [`zenoh::publication::PublisherBuilder`](zenoh::publication::PublisherBuilder)
19#[zenoh_macros::unstable]
20pub trait AdvancedPublisherBuilderExt<'a, 'b, 'c> {
21 /// Allow matching [`AdvancedSubscribers`](crate::AdvancedSubscriber) to recover history and/or missed samples.
22 #[zenoh_macros::unstable]
23 fn cache(self, config: CacheConfig) -> AdvancedPublisherBuilder<'a, 'b, 'c>;
24
25 /// Allow matching [`AdvancedSubscribers`](crate::AdvancedSubscriber) to detect lost samples
26 /// and optionally ask for retransimission.
27 ///
28 /// Retransmission can only be achieved if [`cache`](crate::AdvancedPublisherBuilder::cache) is also enabled.
29 #[zenoh_macros::unstable]
30 fn sample_miss_detection(
31 self,
32 config: MissDetectionConfig,
33 ) -> AdvancedPublisherBuilder<'a, 'b, 'c>;
34
35 /// Allow this publisher to be detected by [`AdvancedSubscribers`](crate::AdvancedSubscriber).
36 ///
37 /// This allows [`AdvancedSubscribers`](crate::AdvancedSubscriber) to retrieve the local history.
38 #[zenoh_macros::unstable]
39 fn publisher_detection(self) -> AdvancedPublisherBuilder<'a, 'b, 'c>;
40
41 /// Turn this [`Publisher`](zenoh::publication::Publisher) into an [`AdvancedPublisher`](crate::AdvancedPublisher).
42 #[zenoh_macros::unstable]
43 fn advanced(self) -> AdvancedPublisherBuilder<'a, 'b, 'c>;
44}
45
46#[zenoh_macros::unstable]
47impl<'a, 'b, 'c> AdvancedPublisherBuilderExt<'a, 'b, 'c> for PublisherBuilder<'a, 'b> {
48 /// Allow matching [`AdvancedSubscribers`](crate::AdvancedSubscriber) to recover history and/or missed samples.
49 #[zenoh_macros::unstable]
50 fn cache(self, config: CacheConfig) -> AdvancedPublisherBuilder<'a, 'b, 'c> {
51 AdvancedPublisherBuilder::new(self).cache(config)
52 }
53
54 /// Allow matching [`AdvancedSubscribers`](crate::AdvancedSubscriber) to detect lost samples
55 /// and optionally ask for retransimission.
56 ///
57 /// Retransmission can only be achieved if [`cache`](crate::AdvancedPublisherBuilder::cache) is also enabled.
58 #[zenoh_macros::unstable]
59 fn sample_miss_detection(
60 self,
61 config: MissDetectionConfig,
62 ) -> AdvancedPublisherBuilder<'a, 'b, 'c> {
63 AdvancedPublisherBuilder::new(self).sample_miss_detection(config)
64 }
65
66 /// Allow this publisher to be detected by [`AdvancedSubscribers`](crate::AdvancedSubscriber).
67 ///
68 /// This allows [`AdvancedSubscribers`](crate::AdvancedSubscriber) to retrieve the local history.
69 #[zenoh_macros::unstable]
70 fn publisher_detection(self) -> AdvancedPublisherBuilder<'a, 'b, 'c> {
71 AdvancedPublisherBuilder::new(self).publisher_detection()
72 }
73
74 /// Turn this [`Publisher`](zenoh::publication::Publisher) into an [`AdvancedPublisher`](crate::AdvancedPublisher).
75 #[zenoh_macros::unstable]
76 fn advanced(self) -> AdvancedPublisherBuilder<'a, 'b, 'c> {
77 AdvancedPublisherBuilder::new(self)
78 }
79}