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 and optionally ask for retransimission.
26 ///
27 /// Retransmission can only be achieved if [`cache`](crate::AdvancedPublisherBuilder::cache) is also enabled.
28 #[zenoh_macros::unstable]
29 fn sample_miss_detection(
30 self,
31 config: MissDetectionConfig,
32 ) -> AdvancedPublisherBuilder<'a, 'b, 'c>;
33
34 /// Allow this publisher to be detected by [`AdvancedSubscribers`](crate::AdvancedSubscriber).
35 ///
36 /// This allows [`AdvancedSubscribers`](crate::AdvancedSubscriber) to retrieve the local history.
37 #[zenoh_macros::unstable]
38 fn publisher_detection(self) -> AdvancedPublisherBuilder<'a, 'b, 'c>;
39
40 /// Turn this [`Publisher`](zenoh::publication::Publisher) into an [`AdvancedPublisher`](crate::AdvancedPublisher).
41 #[zenoh_macros::unstable]
42 fn advanced(self) -> AdvancedPublisherBuilder<'a, 'b, 'c>;
43}
44
45#[zenoh_macros::unstable]
46impl<'a, 'b, 'c> AdvancedPublisherBuilderExt<'a, 'b, 'c> for PublisherBuilder<'a, 'b> {
47 /// Allow matching [`AdvancedSubscribers`](crate::AdvancedSubscriber) to recover history and/or missed samples.
48 #[zenoh_macros::unstable]
49 fn cache(self, config: CacheConfig) -> AdvancedPublisherBuilder<'a, 'b, 'c> {
50 AdvancedPublisherBuilder::new(self).cache(config)
51 }
52
53 /// Allow matching [`AdvancedSubscribers`](crate::AdvancedSubscriber) to detect lost samples and optionally ask for retransimission.
54 ///
55 /// Retransmission can only be achieved if [`cache`](crate::AdvancedPublisherBuilder::cache) is also enabled.
56 #[zenoh_macros::unstable]
57 fn sample_miss_detection(
58 self,
59 config: MissDetectionConfig,
60 ) -> AdvancedPublisherBuilder<'a, 'b, 'c> {
61 AdvancedPublisherBuilder::new(self).sample_miss_detection(config)
62 }
63
64 /// Allow this publisher to be detected by [`AdvancedSubscribers`](crate::AdvancedSubscriber).
65 ///
66 /// This allows [`AdvancedSubscribers`](crate::AdvancedSubscriber) to retrieve the local history.
67 #[zenoh_macros::unstable]
68 fn publisher_detection(self) -> AdvancedPublisherBuilder<'a, 'b, 'c> {
69 AdvancedPublisherBuilder::new(self).publisher_detection()
70 }
71
72 /// Turn this [`Publisher`](zenoh::publication::Publisher) into an [`AdvancedPublisher`](crate::AdvancedPublisher).
73 #[zenoh_macros::unstable]
74 fn advanced(self) -> AdvancedPublisherBuilder<'a, 'b, 'c> {
75 AdvancedPublisherBuilder::new(self)
76 }
77}