Skip to main content

zerodds_dcps_async/
participant.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! AsyncDomainParticipant — newtype um Sync-Variante.
4
5use zerodds_dcps::{
6    DdsType, DomainParticipant, PublisherQos, Result, SubscriberQos, Topic, TopicQos,
7};
8
9use crate::{AsyncPublisher, AsyncSubscriber};
10
11/// Async-Wrapper um `DomainParticipant`. Topics, Pubs und Subs werden
12/// ueber die Sync-API erzeugt; nur der Newtype wechselt das Async-API
13/// frei.
14#[derive(Clone)]
15pub struct AsyncDomainParticipant {
16    inner: DomainParticipant,
17}
18
19impl AsyncDomainParticipant {
20    pub(crate) fn from_sync(inner: DomainParticipant) -> Self {
21        Self { inner }
22    }
23
24    /// Domain-ID.
25    #[must_use]
26    pub fn domain_id(&self) -> i32 {
27        self.inner.domain_id()
28    }
29
30    /// Erstellt ein Topic (ist data-only — keine async-Operation).
31    ///
32    /// # Errors
33    /// Wie `DomainParticipant::create_topic`.
34    pub fn create_topic<T: DdsType>(&self, name: &str, qos: TopicQos) -> Result<Topic<T>> {
35        self.inner.create_topic::<T>(name, qos)
36    }
37
38    /// Erstellt einen Publisher.
39    #[must_use]
40    pub fn create_publisher(&self, qos: PublisherQos) -> AsyncPublisher {
41        AsyncPublisher::from_sync(self.inner.create_publisher(qos))
42    }
43
44    /// Erstellt einen Subscriber.
45    #[must_use]
46    pub fn create_subscriber(&self, qos: SubscriberQos) -> AsyncSubscriber {
47        AsyncSubscriber::from_sync(self.inner.create_subscriber(qos))
48    }
49
50    /// Liefert die zugrundeliegende sync-Variante.
51    #[must_use]
52    pub fn as_sync(&self) -> &DomainParticipant {
53        &self.inner
54    }
55}